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
If the col_names argument to fwf_positions() is a factor, then the return value of that function has a column named col_names that is also a factor, which causes read_fwf() to throw the error
Error: `col_names` must be TRUE, FALSE or a character vector
Reproducible example
# 1. Create a tibble with col_names as a factor
library(readr)
start_posns<- c(1, 2, 4, 8)
end_posns<- c(1, 3, 7, 15)
col_names<-factor(letters[1:4])
fwf_col_info<- fwf_positions(start_posns, end_posns, col_names)
glimpse(fwf_col_info)
## Observations: 4## Variables: 3## $ begin <dbl> 0, 1, 3, 7## $ end <dbl> 1, 3, 7, 15## $ col_names <fct> a, b, c, d# 2. Write some data to filetfile<- tempfile()
writeLines(
c("1AA1111aaaaaaaa", "2BB2222bbbbbbbb", "3CC3333cccccccc", "4DD4444dddddddd"),
tfile
)
# 3. Try to import it
read_fwf(tfile, fwf_col_info)
## Error: `col_names` must be TRUE, FALSE or a character vector
Thoughts on fixes
Either fwf_positions() should convert factor col_names to character, or read_fwf() should allow factors and do the conversion itself, or both.
The text was updated successfully, but these errors were encountered:
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/
lockbot
locked and limited conversation to collaborators
May 13, 2019
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
If the
col_names
argument tofwf_positions()
is a factor, then the return value of that function has a column namedcol_names
that is also a factor, which causesread_fwf()
to throw the errorReproducible example
Thoughts on fixes
Either
fwf_positions()
should convert factorcol_names
to character, orread_fwf()
should allow factors and do the conversion itself, or both.The text was updated successfully, but these errors were encountered: