You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have many data sets that appear to have integers for > 1000 rows, but then it turns out they are numeric. I'm trying to come up with a nice way to handle that, but I'm stuck trying to figure out how to dynamically use the cols_only feature (and maybe that's just not the right way to go anyway):
readr.data <- suppressWarnings(read_delim(doc, skip = 2, delim="\t", col_names = FALSE))
badCols <- problems(readr.data)$col
badCols
[1] "X4" "X4"
unique.bad.cols <- unique(badCols)
readr.cols <- read_delim(doc, skip =2, delim="\t",col_names = FALSE,
col_types = cols_only(unique.bad.cols = "n"))
Warning message:
The following named parsers don't match the column names: unique.bad.cols
#I've also tried:
readr.cols <- read_delim(doc, skip = 2, delim="\t",col_names = FALSE,
col_types = cols_only(setNames("n",unique.bad.cols)))
Error: not compatible with STRSXP
In addition: Warning message:
Unnamed `col_types` should have the same length as `col_names`. Using smaller of the two.
#Other attempts, re-grabbing and parsing all the data instead of just the bad columns:
#a: would like to use the variable unique.bad.cols in col_double
readr.data <- read_delim(doc, skip = 2, delim="\t",col_names = FALSE,
col_types = col_double(unique.bad.cols))
Error in col_double(unique.bad.cols) : unused argument (unique.bad.cols)
#b: use setNames
readr.data <- read_delim(doc, skip = 2, delim="\t",col_names = FALSE,
+ col_types = cols(setNames("n",unique.bad.cols)))
Error: not compatible with STRSXP
In addition: Warning message:
Unnamed `col_types` should have the same length as `col_names`. Using smaller of the two.
#This works just fine, but it won't always be "X4":
readr.cols <- read_delim(doc, skip = 2,delim="\t",col_names = FALSE,
col_types = cols_only("X4"="n"))
After more digging, I realize I had assumed:
cols_only("X4"="n")
was the same as
cols_only(c("X4"="n"))
which it is not (hence the setName function doesn't help).
Any advice would be greatly appreciated. Thanks for the fantastic package!
The text was updated successfully, but these errors were encountered:
I have many data sets that appear to have integers for > 1000 rows, but then it turns out they are numeric. I'm trying to come up with a nice way to handle that, but I'm stuck trying to figure out how to dynamically use the cols_only feature (and maybe that's just not the right way to go anyway):
After more digging, I realize I had assumed:
cols_only("X4"="n")
was the same as
cols_only(c("X4"="n"))
which it is not (hence the
setName
function doesn't help).Any advice would be greatly appreciated. Thanks for the fantastic package!
The text was updated successfully, but these errors were encountered: