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
Here's a minimal example of some small files that I was trying to read with fread:
library(data.table)
V1 <- c("A;B;C", "D", "E;F")
V2 <- c("A;B;C", "D", "E")
fread(paste(V1, collapse = "\n"), sep = ";", header = FALSE, fill = TRUE)
# V1 V2 V3
# 1: A B C
# 2: D
# 3: E F
fread(paste(V2, collapse = "\n"), sep = ";", header = FALSE, fill = TRUE)
# V1
# 1: A;B;C
# 2: D
# 3: E
Notice that the second file only returns 1 column while I was expecting 3. It seems to be ignoring the sep provided and guessing based on the remaining rows. Here are some other "files", one of which also does not work, and one that does:
V3 <- c("A;B;C", ";D", "E")
V4 <- c("A;B;C", "D", ";E")
fread(paste(V3, collapse = "\n"), sep = ";", header = FALSE, fill = TRUE)
# V1
# 1: A;B;C
# 2: ;D
# 3: E
fread(paste(V4, collapse = "\n"), sep = ";", header = FALSE, fill = TRUE)
# V1 V2 V3
# 1: A B C
# 2: D
# 3: E
I tried specifying colClasses:
fread(paste(V2, collapse = "\n"), sep = ";", header = FALSE, fill = TRUE, colClasses = list(character = 1:3))
# Error in fread(paste(V2, collapse = "\n"), sep = ";", header = FALSE, :
# Column number 2 (colClasses[[1]][2]) is out of range [1,ncol=1]
And then tried setting skip = 0 (which works):
fread(paste(V2, collapse = "\n"), sep = ";", header = FALSE, fill = TRUE, skip = 0)
# V1 V2 V3
# 1: A B C
# 2: D
# 3: E
However, I don't want to set skip = 0 because then it doesn't seem to work if a sep value is not found in the first row:
V5 <- c("D", "E", "A;B;C")
fread(paste(V5, collapse = "\n"), sep = ";", header = FALSE, fill = TRUE, skip = 0)
# V1
# 1: D
# 2: E
# 3: A;B;C
fread(paste(V5, collapse = "\n"), sep = ";", header = FALSE, fill = TRUE)
# V1 V2 V3
# 1: D
# 2: E
# 3: A B C
Two questions:
Should fread be ignoring a manually specified sep value?
The documentation says that skip defaults to 0, but formals(fread)$skip returns [1] "__auto__". Should the documentation be updated to explain what "__auto__" represents?
Here's a minimal example of some small files that I was trying to read with
fread
:Notice that the second file only returns 1 column while I was expecting 3. It seems to be ignoring the
sep
provided and guessing based on the remaining rows. Here are some other "files", one of which also does not work, and one that does:I tried specifying
colClasses
:And then tried setting
skip = 0
(which works):However, I don't want to set
skip = 0
because then it doesn't seem to work if asep
value is not found in the first row:Two questions:
fread
be ignoring a manually specifiedsep
value?skip
defaults to 0, butformals(fread)$skip
returns[1] "__auto__"
. Should the documentation be updated to explain what"__auto__"
represents?The text was updated successfully, but these errors were encountered: