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

enquo() is inconsistent with default value for an argument #201

Closed
mgirlich opened this issue Jun 29, 2017 · 1 comment
Closed

enquo() is inconsistent with default value for an argument #201

mgirlich opened this issue Jun 29, 2017 · 1 comment
Labels

Comments

@mgirlich
Copy link

@mgirlich mgirlich commented Jun 29, 2017

enquo() shows an inconsistent behaviour when the default value for an argument is the same as the name of an argument.

library(rlang)
f <- function(x = x) {
  enquo(x)
}

f2 <- function(x = x1) {
  enquo(x)
}

# both work fine
f(x1)
#> <quosure: frame>
#> ~x1
f2(x1)
#> <quosure: frame>
#> ~x1

# unexpected behaviour for f
# I'd rather expect this to be the same as quo(x)
f()
#> <quosure: empty>
#> ~
f2()
#> <quosure: local>
#> ~x1
Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.4.0 (2017-04-21)
#>  system   x86_64, darwin15.6.0        
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  tz       Europe/Berlin               
#>  date     2017-06-29
#> Packages -----------------------------------------------------------------
#>  package   * version    date       source                          
#>  backports   1.0.5      2017-01-18 CRAN (R 3.4.0)                  
#>  base      * 3.4.0      2017-04-21 local                           
#>  compiler    3.4.0      2017-04-21 local                           
#>  datasets  * 3.4.0      2017-04-21 local                           
#>  devtools    1.13.1     2017-05-13 CRAN (R 3.4.0)                  
#>  digest      0.6.12     2017-01-27 CRAN (R 3.4.0)                  
#>  evaluate    0.10       2016-10-11 CRAN (R 3.4.0)                  
#>  graphics  * 3.4.0      2017-04-21 local                           
#>  grDevices * 3.4.0      2017-04-21 local                           
#>  htmltools   0.3.6      2017-04-28 CRAN (R 3.4.0)                  
#>  knitr       1.16       2017-05-18 CRAN (R 3.4.0)                  
#>  magrittr    1.5        2014-11-22 CRAN (R 3.4.0)                  
#>  memoise     1.1.0      2017-04-21 CRAN (R 3.4.0)                  
#>  methods   * 3.4.0      2017-04-21 local                           
#>  Rcpp        0.12.11    2017-05-22 CRAN (R 3.4.0)                  
#>  rlang     * 0.1.1.9000 2017-06-29 Github (tidyverse/rlang@c4887ed)
#>  rmarkdown   1.5        2017-04-26 CRAN (R 3.4.0)                  
#>  rprojroot   1.2        2017-01-16 CRAN (R 3.4.0)                  
#>  stats     * 3.4.0      2017-04-21 local                           
#>  stringi     1.1.5      2017-04-07 CRAN (R 3.4.0)                  
#>  stringr     1.2.0      2017-02-18 CRAN (R 3.4.0)                  
#>  tools       3.4.0      2017-04-21 local                           
#>  utils     * 3.4.0      2017-04-21 local                           
#>  withr       1.0.2      2016-06-20 CRAN (R 3.4.0)                  
#>  yaml        2.1.14     2016-11-12 CRAN (R 3.4.0)
@hongooi73
Copy link

@hongooi73 hongooi73 commented Jul 3, 2017

function(x=x) {...} doesn't really make sense though. Remember the default value is evaluated inside the environment of the function itself, so this will result in an infinite recursion if you actually try to use it.

For example:

f <- function(x=x) sin(x)

f()
# Error in f() : 
#   promise already under evaluation: recursive default argument reference or earlier problems?
lionel- added a commit to lionel-/rlang that referenced this issue Nov 24, 2017
@lionel- lionel- closed this in #297 Nov 28, 2017
lionel- added a commit to lionel-/rlang that referenced this issue Nov 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants