Adding input files to gcamdata: Column type error #214
Replies: 5 comments
-
This error can be resolved by removing the character data cells from the "n" data columns. Here is a way to determine which columns are causing the error: Running the following code would tell you the data type for each column. |
Beta Was this translation helpful? Give feedback.
-
Sometimes we get similar issues when you edit a csv or open it in excel and close it again. In this case excel saves the csv but puts in quotation marks in empty cells. These are read in as populated cells and throw errors. |
Beta Was this translation helpful? Give feedback.
-
That's very useful. Thanks Ian and Zarrar! |
Beta Was this translation helpful? Give feedback.
-
This error can also be thrown if there are "#" in the input file, excluding the start of the header. If there is a "#" in a cell, read_csv ignores everything that comes after it, so the character needs to be removed or replaced. |
Beta Was this translation helpful? Give feedback.
-
@ssmithClimate asked about having a clearer error message. Just so this doesn't get lost in the Slack thread...one solution would be to have # Check that our comment character doesn't appear in the data
preread <- read_lines(fqfn)
preread <- preread[grep(paste0("^", COMMENT_CHAR), preread, invert = TRUE)] # remove lines with "#" at beginning
badlines <- grep(COMMENT_CHAR, preread) # identify any remaining lines with "#"
if(length(badlines)) stop("Comment character ", COMMENT_CHAR, " appears in data!") |
Beta Was this translation helpful? Give feedback.
-
After adding new input .csv files to GCAM data, I ran into the following error while trying to load them in a new chunk:
In case anyone runs into this problem: this error indicates a column type error.
When specifying column types in the header, if you assign the "n" data type to a column that contains even a single character data cell, you will get this error.
Beta Was this translation helpful? Give feedback.
All reactions