Search code examples
r-exams

error in nops_eval 'register' does not contain all columns registration/name/id


I am trying to use the nops_eval function like this:

eval <- nops_eval(register = "nops_eval/pauta.csv",
          solutions = "nops_eval/Ex_AEI_MTI_v.rds",
          scans = "nops_eval/nops_scan_20210712161737.zip",
          language = "pt",
          eval = exams_eval(partial = F, negative = -.25,rule = "false"),
          dir = "eval",
          mark = F,
          file = "exame_M2_ep_rec",
          results = "nops_eval_M2rec",
          interactive = T)

My register file is a csv with semi-colon separated values:

enter image description here

But I am getting this error:

Error in nops_eval(register = "nops_eval/pauta.csv", solutions = "nops_eval/Ex_AEI_MTI_v.rds", : 'register' does not contain all columns registration/name/id

That I can't really explain. I am running Rstudio on Windows 10.

Any idea of what may be causing the non-recognition of "registration;name;id"? Thanks!


Solution

  • The reason must be that when read into R the data has different column names. To check this "by hand" you can use

    x <- read.csv2("nops_eval/pauta.csv", colClasses = "character")
    names(x)
    ## [1] "registration" "name"         "id"          
    

    This is what nops_eval() uses internally. Possibly, the problems are created by the Byte order mark added by some software packages (notably Excel) at the beginning of CSV files to signal how they were stored. Depending on the locale settings these may lead to hiccups and unwanted characters when reading the header line of the CSV.

    To work around such problems it's best to fix the header line and re-save the CSV file, e.g., using write.table() or write.csv2() in R.