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
## Error in vapply(cols[[i]], deparse, character(1)) :
## values must be length 1,
## but FUN(X[[1]]) result is length 2
However, the following two examples do not produce errors:
# Example 2:# Remove one of the levels to leave just six.readr::cols(a=readr::col_factor(
levels= c("apple", "pear", "banana", "peach", "apricot", "orange"), ordered=TRUE)
)
# Example 3:# Back to seven levels again, but with shorter labels.readr::cols(a=readr::col_factor(
levels= c("apple", "pear", "banana", "peach", "apri", "oran", "plum"), ordered=TRUE)
)
But with the third example, if I add just one extra character to any of the labels, e.g. 'apri' to 'apric', I get the error again:
# Example 4:readr::cols(a=readr::col_factor(
levels= c("apple", "pear", "banana", "peach", "apric", "oran", "plum"), ordered=TRUE)
)
## Error in vapply(cols[[i]], deparse, character(1)) : ## values must be length 1,## but FUN(X[[1]]) result is length 2
After trying a number of combinations, I believe the error occurs once there are more than 32 cumulative characters used to define the labels of the levels:
# From example 3:
nchar(paste(c("apple", "pear", "banana", "peach", "apri", "oran", "plum"), collapse=""))
## [1] 32# From example 4:
nchar(paste(c("apple", "pear", "banana", "peach", "apric", "oran", "plum"), collapse=""))
## [1] 33
You can make such a specification ... but you just can't print it at the moment.
x<-readr::cols(a=readr::col_factor(
levels= c("apple", "pear", "banana", "peach", "apricot", "orange", "plum"), ordered=TRUE)
)
print(x)
#> Error in vapply(cols[[i]], deparse, character(1)): values must be length 1,#> but FUN(X[[1]]) result is length 2
I realize that is still a problem! But it means you can still use col_factor() in the meantime, as long you can suppress the printing of the col spec.
jimhester
changed the title
col_factor fails with cumulative length of labels greater than 32 characters for levels argument.
format.col_spec() fails with long expressions.
Feb 6, 2017
As @jennybc said, this was an error in the format method for col_spec objects caused by deparse breaking long expressions into multiple lines. Fixed by #598.
I am defining a column as a factor, as follows.
Which produces the following error:
However, the following two examples do not produce errors:
But with the third example, if I add just one extra character to any of the labels, e.g. 'apri' to 'apric', I get the error again:
After trying a number of combinations, I believe the error occurs once there are more than 32 cumulative characters used to define the labels of the levels:
Below is a copy of the traceback:
I am using the current development version of
readr
available through github and R version 3.3.2 on Windows 10.The text was updated successfully, but these errors were encountered: