The following named parsers don't match the column names

Can you help me find out what I'm missing?

I want to convert the type of a column a. When I specify the type I want, I get a warning suggesting that the name a in my tibble does not match the name a in my column-type specification.

I've seen some issues related to this topic, but they are closed and suggest there should be no bug.

library(readr)

# Silent
type_convert(tibble::tibble(a = 1), col_types = cols())
#> # A tibble: 1 x 1
#>       a
#>   <dbl>
#> 1     1

# Why this warning?
# (I expect no warning because name of the column  (`a`) does match).
type_convert(tibble::tibble(a = 1), col_types = cols(a = col_integer()))
#> Warning: The following named parsers don't match the column names: a
#> # A tibble: 1 x 1
#>       a
#>   <dbl>
#> 1     1
type_convert(tibble::tibble(a = 1), col_types = cols(a = "i"))
#> Warning: The following named parsers don't match the column names: a
#> # A tibble: 1 x 1
#>       a
#>   <dbl>
#> 1     1

Created on 2018-10-02 by the reprex package (v0.2.1)

Strange, and I'm able to reproduce. Even though this is numeric to numeric (double to integer), it could possibly be related to:

and

2 Likes

Thanks Mara, for helping me see my mistake. I was expecting type_convert() to convert from any type to any type. I now realized that it is designed to convert to any type but only form text. (The warning message and the function name confused me).

type_convert() doesn't do arbitrary conversions, it only converts character columns to one of the other types. So the error is happening because in column X because you are trying to convert an integer to a character with type_convert() instead of using as.character() . --Jim Hester

Also the title states: Re-convert character columns in existing data frame.

3 Likes

Ah, yes! I read that, and then promptly forgot. Might be a good candidate for error-message improvement.

1 Like