Skip to content

col_types_concise(): collector for "unknown" type, cf. colClasses=NA #188

Description

@HenrikBengtsson

I'm trying out readr and I like what I see :)

I'm missing a way to specify "I let you" choose the best class for the column, cf.

> cat("a\t2\t1.2", file="foo.tsv")

> str(read.table("foo.tsv", colClasses=c("character", "integer", NA)))
'data.frame':   1 obs. of  3 variables:
 $ V1: chr "a"
 $ V2: int 2
 $ V3: num 1.2

> str(readr::read_tsv("foo.tsv", col_names=FALSE))
Classes 'tbl_df', 'tbl' and 'data.frame':       1 obs. of  3 variables:
 $ X1: chr "a"
 $ X2: int 2
 $ X3: num 1.2

> str(readr::read_tsv("foo.tsv", col_names=FALSE, col_types="cid"))
Classes 'tbl_df', 'tbl' and 'data.frame':       1 obs. of  3 variables:
 $ X1: chr "a"
 $ X2: int 2
 $ X3: num 1.2

but ideally also something like:

> str(readr::read_tsv("foo.tsv", col_names=FALSE, col_types="ci?"))
 $ X1: chr "a"
 $ X2: int 2
 $ X3: num 1.2

PS. I picked '?' as in R.utils::colClasses("ci?") == c("character", "integer", "NA"). Related and minor: Did you consider using another symbol than underscore for skipping a column, because it becomes hard to count when there are several of them in a row, e.g. c______i v. c------i.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions