Skip to content

data.table conversion turns the class of <expr> column into <list> column #4040

Description

@JodyStats
library(data.table)
library(dplyr)
#> 
#> Attaching package: "dplyr"
#> The following objects are masked from "package:data.table":
#> 
#>     between, first, last
#> The following objects are masked from "package:stats":
#> 
#>     filter, lag
#> The following objects are masked from "package:base":
#> 
#>     intersect, setdiff, setequal, union
library(tibble)
library(drake)

plan <- drake::drake_plan(
  expr = dat[, col := val]
)

The drake_plan returns a tibble to be manipulated. The problem is that one of the variable being "expr" class and when I convert it to data.table the "expr" class turns into "list" class. I do not intend to manipulate this "expr" column and it"s required for downstream processes, its "expr" class must be unchanged after being converted into data.table from tibble. Is this a bug that can be fixed? Otherwise, what is the solution and best practice? Thank you in advance.

# command column class of <expr>
plan
#> # A tibble: 1 x 2
#>   target command              
#>   <chr>  <expr>               
#> 1 expr   dat[, `:=`(col, val)]

# command column class of <expr>
plan %>% mutate(col = "val")
#> # A tibble: 1 x 3
#>   target command               col  
#>   <chr>  <expr>                <chr>
#> 1 expr   dat[, `:=`(col, val)] val

# command column class of <list>
plan <- data.table(plan)[, col := "val"]
plan
#>    target command    col
#>    <char>  <list> <char>
#> 1:   expr  <call>    val

# command column class of <list>
as_tibble(plan)
#> # A tibble: 1 x 3
#>   target command    col  
#>   <chr>  <list>     <chr>
#> 1 expr   <language> val

Created on 2019-11-12 by the reprex package (v0.3.0)

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

    non-atomic columne.g. list columns, S4 vector columns

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions