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 · 7 comments

Comments

3 participants
@jennybc
Member

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

This comment has been minimized.

Member

hadley commented Oct 28, 2016

Likely just a mistake

@hadley hadley added feature read bug and removed feature labels Dec 22, 2016

@jimhester

This comment has been minimized.

Member

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

This comment has been minimized.

Member

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

This comment has been minimized.

Member

jennybc commented Feb 1, 2017

I would expect x and y to be double.

@hadley

This comment has been minimized.

Member

hadley commented Feb 1, 2017

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

@jennybc

This comment has been minimized.

Member

jennybc commented Feb 1, 2017

Then character?

@hadley

This comment has been minimized.

Member

hadley commented Feb 1, 2017

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

@jimhester jimhester added this to IN PROGRESS in jimhester Feb 2, 2017

@jimhester jimhester moved this from IN PROGRESS to DONE in jimhester Feb 6, 2017

@jimhester jimhester closed this in f4bde40 Nov 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment