Skip to content
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

view(), expr_deparse(), and native pipes #957

Closed
dhicks opened this issue Oct 10, 2021 · 4 comments
Closed

view(), expr_deparse(), and native pipes #957

dhicks opened this issue Oct 10, 2021 · 4 comments
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@dhicks
Copy link

dhicks commented Oct 10, 2021

view() has some sort of negative interaction with the new native pipe when the incoming expression is somewhat complicated and the title isn't explicitly specified. In the error case, the message is Error in View : invalid caption argument.

Poking around in the debugger, it seems like the problem is with expr_deparse() and the fact that the native pipe (unlike the magrittr pipe) is just syntactic sugar for nesting function calls. When the expression being piped into view() is long, expr_deparse() breaks it into multiple lines (I guess because it's intended for printing?), but then View() doesn't know what to do with a multi-line title. Using capital-V View(), the default title appears to be the whole incoming expression.

library(tibble)
library(dplyr)

## Works correctly
starwars |>
    view()
    
## Also works correctly
starwars |>
    mutate(height_m = height/100) |>
    view()

## Error in View : invalid caption argument
starwars |> 
    mutate(height_m = height/100) |> 
    mutate(mass_g = mass * 1000) |>  
    view()

## Error in View : invalid caption argument
starwars |> 
    mutate(height_m = height/100, 
           mass_g = mass * 1000) |>  
    view()

## Works correctly if the caption is explicit
starwars |> 
    mutate(height_m = height/100,
           mass_g = mass*1000) |> 
    view('converted')
─ Session info ────────────────────────────────────────────
 setting  value                       
 version  R version 4.1.0 (2021-05-18)
 os       macOS Big Sur 11.6          
 system   x86_64, darwin17.0          
 ui       RStudio                     
 language (EN)                        
 collate  en_US.UTF-8                 
 ctype    en_US.UTF-8                 
 tz       America/Los_Angeles         
 date     2021-10-10                  

─ Packages ────────────────────────────────────────────────
 package     * version date       lib source        
 assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.1.0)
 bslib         0.3.0   2021-09-02 [1] CRAN (R 4.1.0)
 cachem        1.0.6   2021-08-19 [1] CRAN (R 4.1.0)
 callr         3.7.0   2021-04-20 [1] CRAN (R 4.1.0)
 cli           3.0.1   2021-07-17 [1] CRAN (R 4.1.0)
 clipr         0.7.1   2020-10-08 [1] CRAN (R 4.1.0)
 crayon        1.4.1   2021-02-08 [1] CRAN (R 4.1.0)
 DBI           1.1.1   2021-01-15 [1] CRAN (R 4.1.0)
 digest        0.6.27  2020-10-24 [1] CRAN (R 4.1.0)
 dplyr       * 1.0.7   2021-06-18 [1] CRAN (R 4.1.0)
 ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.1.0)
 evaluate      0.14    2019-05-28 [1] CRAN (R 4.1.0)
 fansi         0.5.0   2021-05-25 [1] CRAN (R 4.1.0)
 fastmap       1.1.0   2021-01-25 [1] CRAN (R 4.1.0)
 fs            1.5.0   2020-07-31 [1] CRAN (R 4.1.0)
 generics      0.1.0   2020-10-31 [1] CRAN (R 4.1.0)
 glue          1.4.2   2020-08-27 [1] CRAN (R 4.1.0)
 highr         0.9     2021-04-16 [1] CRAN (R 4.1.0)
 htmltools     0.5.2   2021-08-25 [1] CRAN (R 4.1.0)
 httpuv        1.6.3   2021-09-09 [1] CRAN (R 4.1.0)
 jquerylib     0.1.4   2021-04-26 [1] CRAN (R 4.1.0)
 jsonlite      1.7.2   2020-12-09 [1] CRAN (R 4.1.0)
 knitr         1.33    2021-04-24 [1] CRAN (R 4.1.0)
 later         1.3.0   2021-08-18 [1] CRAN (R 4.1.0)
 lifecycle     1.0.1   2021-09-24 [1] CRAN (R 4.1.0)
 magrittr      2.0.1   2020-11-17 [1] CRAN (R 4.1.0)
 mime          0.11    2021-06-23 [1] CRAN (R 4.1.0)
 miniUI        0.1.1.1 2018-05-18 [1] CRAN (R 4.1.0)
 pillar        1.6.3   2021-09-26 [1] CRAN (R 4.1.0)
 pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.1.0)
 processx      3.5.2   2021-04-30 [1] CRAN (R 4.1.0)
 promises      1.2.0.1 2021-02-11 [1] CRAN (R 4.1.0)
 ps            1.6.0   2021-02-28 [1] CRAN (R 4.1.0)
 purrr         0.3.4   2020-04-17 [1] CRAN (R 4.1.0)
 R6            2.5.1   2021-08-19 [1] CRAN (R 4.1.0)
 Rcpp          1.0.7   2021-07-07 [1] CRAN (R 4.1.0)
 reprex        2.0.0   2021-04-02 [1] CRAN (R 4.1.0)
 rlang         0.4.11  2021-04-30 [1] CRAN (R 4.1.0)
 rmarkdown     2.9     2021-06-15 [1] CRAN (R 4.1.0)
 rstudioapi    0.13    2020-11-12 [1] CRAN (R 4.1.0)
 sass          0.4.0   2021-05-12 [1] CRAN (R 4.1.0)
 sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.1.0)
 shiny       * 1.6.0   2021-01-25 [1] CRAN (R 4.1.0)
 tibble      * 3.1.5   2021-09-30 [1] CRAN (R 4.1.0)
 tidyselect    1.1.1   2021-04-30 [1] CRAN (R 4.1.0)
 utf8          1.2.2   2021-07-24 [1] CRAN (R 4.1.0)
 vctrs         0.3.8   2021-04-29 [1] CRAN (R 4.1.0)
 withr         2.4.2   2021-04-18 [1] CRAN (R 4.1.0)
 xfun          0.24    2021-06-15 [1] CRAN (R 4.1.0)
 xtable        1.8-4   2019-04-21 [1] CRAN (R 4.1.0)
 yaml          2.2.1   2020-02-01 [1] CRAN (R 4.1.0)

[1] /Library/Frameworks/R.framework/Versions/4.1/Resources/library
@krlmlr
Copy link
Member

krlmlr commented Oct 17, 2021

Thanks, I can't replicate it in RStudio 1.4.1717. What version of RStudio are you using?

@krlmlr krlmlr added the reprex needs a minimal reproducible example label Oct 17, 2021
@dhicks
Copy link
Author

dhicks commented Oct 18, 2021 via email

@krlmlr krlmlr added bug an unexpected problem or unintended behavior and removed reprex needs a minimal reproducible example labels Oct 25, 2021
@krlmlr
Copy link
Member

krlmlr commented Oct 25, 2021

Indeed, changing options(width = ...) does the trick.

@krlmlr krlmlr added this to the 3.1.6 milestone Oct 25, 2021
@krlmlr krlmlr closed this as completed in 8795f55 Oct 25, 2021
krlmlr added a commit that referenced this issue Mar 2, 2022
tibble 3.1.6

- `set_num_opts()` and `set_char_opts()` are reexported from pillar (#959).
- `view()` uses `rlang::expr_deparse(width = Inf)` to avoid errors with long `|>` pipes (#957).
- `new_tibble()` checks that the `nrow` argument is nonnegative and less than 2^31 (#916).
- `tbl_sum.tbl_df()` has an ellipsis in its formals for extensibility.
@github-actions
Copy link
Contributor

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants