Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

producing a column specification for type_convert() #517

Closed
jennybc opened this issue Sep 10, 2016 · 8 comments
Closed

producing a column specification for type_convert() #517

jennybc opened this issue Sep 10, 2016 · 8 comments

Comments

@jennybc
Copy link
Member

@jennybc jennybc commented Sep 10, 2016

I'm learning the hard way that readr::type_convert() no longer takes column specifications as a character string, like cccnnn. Apparently I do this in googlesheets examples, tests, etc. Is there a specific reason to require the long form in type_convert()? If I have to workaround this myself, is there a better way than what I've got here? This looks a bit nutty.

x <- "cccnnn"
do.call(readr::cols, as.list(strsplit(x, "")[[1]]))
#> cols(
#>    = col_character(),
#>    = col_character(),
#>    = col_character(),
#>    = col_number(),
#>    = col_number(),
#>    = col_number()
#> )
@hadley
Copy link
Member

@hadley hadley commented Oct 28, 2016

Likely just a mistake

@jimhester
Copy link
Member

@jimhester jimhester commented Jan 30, 2017

This was changed in response to #369 and #431, where we explicitly disabled support for character vectors in type_convert(). There is even a blurb in ?type_convert (including a typo)

Unlike other functions ‘type_convert()’ does not allow
character specificatinos of ‘col_types’.

@jennybc Probably the easiest way to do what you want is to use as.col_spec(), but it is unexported :(.

readr::as.col_spec("cccnnn")
#> Error: 'as.col_spec' is not an exported object from 'namespace:readr'
readr:::as.col_spec("cccnnn")
#> cols(
#>    = col_character(),
#>    = col_character(),
#>    = col_character(),
#>    = col_number(),
#>    = col_number(),
#>    = col_number()
#> )
@hadley
Copy link
Member

@hadley hadley commented Feb 1, 2017

@jennybc what do you think we should do in this scenario?

library(tidyverse)
df <- tibble(x = 1:2, y = 1:2)
type_convert(df, col_types = "dd")
@jennybc
Copy link
Member Author

@jennybc jennybc commented Feb 1, 2017

I would expect x and y to be double.

@hadley
Copy link
Member

@hadley hadley commented Feb 1, 2017

What about type_convert(df, col_types = "cc") ?

@jennybc
Copy link
Member Author

@jennybc jennybc commented Feb 1, 2017

Then character?

@hadley
Copy link
Member

@hadley hadley commented Feb 1, 2017

Hmmm, that's considerably expanding the scope — currently it only operates on character columns.

@jimhester jimhester closed this in f4bde40 Nov 14, 2018
@lock
Copy link

@lock lock bot commented May 13, 2019

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/

@lock lock bot locked and limited conversation to collaborators May 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants