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

Knitting problem with code chunks having tidy evaluation methods #1528

Closed
tungttnguyen opened this issue Mar 21, 2018 · 4 comments
Closed

Knitting problem with code chunks having tidy evaluation methods #1528

tungttnguyen opened this issue Mar 21, 2018 · 4 comments
Milestone

Comments

@tungttnguyen
Copy link

tungttnguyen commented Mar 21, 2018

Hello Yihui,

I encountered this error. Do you know how to fix it? Thanks!

Quitting from lines 21-44 (tidyeval_test.Rmd) 
Error in !x : invalid argument type
Calls: <Anonymous> ... by_layer -> f -> <Anonymous> -> f -> lapply -> FUN -> FUN
Execution halted

Rmd file used

---
title: "tidyeval"
output: html_document
---

```{r setup, include=FALSE}

knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(cache = TRUE)
knitr::opts_chunk$set(tidy = TRUE, highlight = TRUE,
                      prompt = FALSE, collapse = TRUE)
knitr::opts_chunk$set(tidy.opts = list(width.cutoff = 60))

```

## tidyeval in rmarkdown

### Example #1:

```{r cars}

library(rlang)
library(tidyverse)
library(lubridate)
library(nycflights13)

flights_2 <- flights %>% 
  mutate(departure_month = ymd(str_c(year, month, "01", sep = "-"))) %>% 
  group_by(departure_month) %>% 
  summarize(arrival_delay = mean(arr_delay, na.rm = TRUE))
flights_2

chart_func <- function(df, x, y) {
  x <- enexpr(x)
  y <- enexpr(y)
  
  ggplot(df, aes(!!x, !!y)) + 
    geom_line()
  
}

chart_func(df = flights_2, x = departure_month, y = arrival_delay)

```
Session Info
> devtools::session_info()
Session info ---------------------------------------------------------------
 setting  value                       
 version  R version 3.4.4 (2018-03-15)
 system   x86_64, mingw32             
 ui       RStudio (1.1.442)           
 language (EN)                        
 collate  English_United States.1252  
 tz       America/Los_Angeles         
 date     2018-03-21                  

Packages -------------------------------------------------------------------
 package      * version    date       source                               
 ansistrings    1.0.0.9000 2018-02-28 Github (r-lib/ansistrings@4e4d309)   
 assertthat     0.2.0      2017-04-11 CRAN (R 3.4.0)                       
 backports      1.1.2      2017-12-13 CRAN (R 3.4.3)                       
 base         * 3.4.4      2018-03-15 local                                
 bindr          0.1.1.9000 2018-03-20 Github (krlmlr/bindr@b6e6fd6)        
 bindrcpp     * 0.2.0.9000 2018-03-20 Github (krlmlr/bindrcpp@5d51655)     
 broom          0.4.3      2017-11-20 CRAN (R 3.4.3)                       
 cellranger     1.1.0      2016-07-27 CRAN (R 3.4.0)                       
 cli            1.0.0.9002 2018-03-15 Github (r-pkgs/boxes@53c129a)        
 colorspace     1.3-2      2016-12-14 CRAN (R 3.4.3)                       
 compiler       3.4.4      2018-03-15 local                                
 cowplot        0.9.2.9900 2018-03-20 Github (wilkelab/cowplot@bb819a1)    
 crayon         1.3.4      2018-02-12 Github (gaborcsardi/crayon@95b3eae)  
 curl           3.1        2017-12-12 CRAN (R 3.4.3)                       
 datasets     * 3.4.4      2018-03-15 local                                
 devtools       1.13.5     2018-02-18 CRAN (R 3.4.3)                       
 digest         0.6.15     2018-01-28 CRAN (R 3.4.3)                       
 dplyr        * 0.7.4.9002 2018-03-21 Github (tidyverse/dplyr@84fdff5)     
 evaluate       0.10.1     2017-06-24 CRAN (R 3.4.4)                       
 forcats      * 0.3.0      2018-02-19 CRAN (R 3.4.3)                       
 foreign        0.8-69     2017-06-22 CRAN (R 3.4.4)                       
 ggplot2      * 2.2.1.9000 2018-03-13 Github (tidyverse/ggplot2@39e4a3b)   
 glue           1.2.0.9000 2018-02-12 Github (tidyverse/glue@9d96cbf)      
 graphics     * 3.4.4      2018-03-15 local                                
 grDevices    * 3.4.4      2018-03-15 local                                
 grid           3.4.4      2018-03-15 local                                
 gridExtra      2.3        2017-09-09 CRAN (R 3.4.2)                       
 gtable         0.2.0      2016-02-26 CRAN (R 3.4.3)                       
 haven          1.1.1      2018-01-18 CRAN (R 3.4.3)                       
 hms            0.4.2      2018-03-13 Github (tidyverse/hms@c0cfc01)       
 hoardr         0.2.0      2017-05-10 CRAN (R 3.4.0)                       
 htmltools      0.3.6      2017-04-28 CRAN (R 3.4.0)                       
 httr           1.3.1      2017-08-20 CRAN (R 3.4.1)                       
 jsonlite       1.5        2017-06-01 CRAN (R 3.4.1)                       
 knitr          1.20       2018-02-20 CRAN (R 3.4.4)                       
 labeling       0.3        2014-08-23 CRAN (R 3.4.1)                       
 lattice        0.20-35    2017-03-25 CRAN (R 3.4.4)                       
 lazyeval       0.2.1.9000 2017-12-27 Github (hadley/lazyeval@93c455c)     
 lubridate    * 1.7.3      2018-03-20 Github (tidyverse/lubridate@9797d69) 
 magrittr     * 1.5        2014-11-22 CRAN (R 3.4.3)                       
 memoise        1.1.0      2017-04-21 CRAN (R 3.4.0)                       
 methods      * 3.4.4      2018-03-15 local                                
 mnormt         1.5-5      2016-10-15 CRAN (R 3.4.1)                       
 modelr         0.1.1      2017-07-24 CRAN (R 3.4.1)                       
 munsell        0.4.3      2016-02-13 CRAN (R 3.4.3)                       
 nlme           3.1-131.1  2018-02-16 CRAN (R 3.4.4)                       
 nycflights13 * 0.2.2      2017-01-27 CRAN (R 3.4.3)                       
 parallel       3.4.4      2018-03-15 local                                
 pillar         1.2.1      2018-02-27 CRAN (R 3.4.3)                       
 pkgconfig      2.0.1      2017-03-21 CRAN (R 3.4.0)                       
 plyr           1.8.4      2016-06-08 CRAN (R 3.4.3)                       
 prettyunits    1.0.2      2015-07-13 CRAN (R 3.4.3)                       
 progress       1.1.2.9002 2018-02-20 Github (r-lib/progress@72c9873)      
 psych          1.7.8      2017-09-09 CRAN (R 3.4.1)                       
 purrr        * 0.2.4.9000 2018-03-13 Github (tidyverse/purrr@84ce1ad)     
 R6             2.2.2      2017-06-17 CRAN (R 3.4.1)                       
 rappdirs       0.3.1      2016-03-28 CRAN (R 3.4.3)                       
 Rcpp           0.12.16    2018-03-13 CRAN (R 3.4.4)                       
 readr        * 1.2.0      2018-03-15 Github (tidyverse/readr@31dfea0)     
 readxl         1.0.0.9000 2018-03-17 Github (tidyverse/readxl@73a8c3c)    
 reshape2       1.4.3      2017-12-11 CRAN (R 3.4.3)                       
 rlang        * 0.2.0.9000 2018-03-15 Github (r-lib/rlang@1b81816)         
 rmarkdown      1.9.5      2018-03-15 Github (rstudio/rmarkdown@b73f4ce)   
 rnoaa        * 0.7.0      2017-05-06 CRAN (R 3.4.0)                       
 rprojroot      1.3-2      2018-01-03 CRAN (R 3.4.3)                       
 rstudioapi     0.7        2017-09-07 CRAN (R 3.4.2)                       
 rvest          0.3.2      2016-06-17 CRAN (R 3.4.3)                       
 scales         0.5.0.9000 2017-12-27 Github (hadley/scales@d767915)       
 selectr        0.3-2      2018-03-05 CRAN (R 3.4.3)                       
 stats        * 3.4.4      2018-03-15 local                                
 stringi        1.1.7      2018-03-12 CRAN (R 3.4.3)                       
 stringr      * 1.3.0.9000 2018-03-13 Github (tidyverse/stringr@097c0c0)   
 tibble       * 1.4.2      2018-01-22 CRAN (R 3.4.3)                       
 tidyr        * 0.8.0.9000 2018-03-17 Github (tidyverse/tidyr@32b73ea)     
 tidyselect     0.2.4.9000 2018-02-28 Github (tidyverse/tidyselect@72bedbb)
 tidyverse    * 1.2.1      2018-02-27 Github (tidyverse/tidyverse@03ccf9c) 
 tools          3.4.4      2018-03-15 local                                
 utils        * 3.4.4      2018-03-15 local                                
 withr          2.1.2      2018-03-15 Github (r-lib/withr@79d7b0d)         
 XML            3.98-1.10  2018-02-19 CRAN (R 3.4.3)                       
 xml2           1.2.0      2018-01-24 CRAN (R 3.4.3)                       
 yaml           2.1.19     2018-03-13 Github (viking/r-yaml@e701045)
@yihui
Copy link
Owner

yihui commented Mar 21, 2018

Duplicate of yihui/formatR#75

tidy=TRUE doesn't work with !!.

@yihui yihui marked this as a duplicate of yihui/formatR#75 Mar 21, 2018
@yihui yihui added this to the v1.21 milestone Mar 21, 2018
@yihui yihui closed this as completed Mar 21, 2018
@tungttnguyen
Copy link
Author

Thanks @yihui !

@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2020
@yihui
Copy link
Owner

yihui commented Dec 22, 2022

This problem has gone with the latest version of R (I'm not sure about the minimal version of R for this to work, though).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants