spgarbet / tangram

Table Grammar package for R
66 stars 3 forks source link

Tangram should handle columns with whitespaces #59

Closed madten closed 4 years ago

madten commented 4 years ago

Description

Attempt to tangram column with whitespace:

library(dplyr)
library(tangram)

df <- tibble(`foo bar` = 1:3, x = 4:6)

tangram(x ~ `foo bar`, df)

fails with

 tangram(x ~ `foo bar`, df, id="foo bar")
Error in self$expect("EOF") : ExpectingEOFbefore ''

Renaming resolves the problem:

tangram(x ~ `foobar`, df %>% rename(foobar = `foo bar`), id="foobar")
=================
        N    x   
           (N=3) 
-----------------
foobar  3  ρ=1.00
=================

Desired behaviour

tangram(x ~ `foo bar`, df)
===================
         N    x   
            (N=3) 
-------------------
foo bar   3  ρ=1.00
===================

Environment

R version: 3.6.2 Tangram version: 836c288d

Attached packages

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] tangram_0.7.0 knitr_1.28    magrittr_1.5  R6_2.4.1      dplyr_0.8.4  

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.3       digest_0.6.24    crayon_1.3.4     assertthat_0.2.1
 [5] pillar_1.4.3     stringi_1.4.6    rlang_0.4.4      tools_3.6.2     
 [9] stringr_1.4.0    glue_1.3.1       purrr_0.3.3      xfun_0.12       
[13] compiler_3.6.2   base64enc_0.1-3  pkgconfig_2.0.3  htmltools_0.4.0 
[17] tidyselect_1.0.0 tibble_2.1.3  
spgarbet commented 4 years ago

I can add this behavior. It'll take a bit, but I know exactly what to do.

madten commented 4 years ago

Thank you @spgarbet

If that's too much work, a readable error message would be a decent alternative.

(Thank you for the amazing work on this package!)

spgarbet commented 4 years ago

Oh, it's not too much work. I think I have a simple solution (and I've wanted this for some time).

I also except transform bundles. I'm getting ready to publish some I use for DSMB reports.

spgarbet commented 4 years ago

@madten try it now and let me know if it works.

madten commented 4 years ago

Perfect, thank you @spgarbet!