From lionel at rstudio.com  Tue Sep 19 10:49:14 2017
From: lionel at rstudio.com (Lionel Henry)
Date: Tue, 19 Sep 2017 10:49:14 +0200
Subject: [Rd] issue with promises for time parameter of rep()
In-Reply-To: <CAPYa3vTG0zEMoJonD1yEc8+9=yZ-2Lnp8FLG8U1o4iGT+d9ktg@mail.gmail.com>
References: <CAPYa3vTG0zEMoJonD1yEc8+9=yZ-2Lnp8FLG8U1o4iGT+d9ktg@mail.gmail.com>
Message-ID: <992E43D2-18E4-4AEF-ABC3-A1C16FE87E5E@rstudio.com>

Here is the same issue with closures:

    g <- function(n) {
      missing(n)
    }
    f <- function(n, force) {
      if (force) {
        tryCatch(n, error = function(...) NULL)
      }
      g(n)
    }

    g(`_x`)
    #> [1] FALSE

    f(`_x`, force = FALSE)
    #> [1] FALSE

    f(`_x`, force = TRUE)
    #> [1] TRUE

Lionel

> On 18 sept. 2017, at 19:06, Homer White <homerhanumat at gmail.com> wrote:
> 
> Greetings,
> 
> The following is based on a question I raised on Stackoverflow:
> 
> https://stackoverflow.com/questions/46280120/calling-printls-str-in-function-affect-behavior-of-rep/46283979#46283979
> 
> Start a new R session with an empty Global Env.  Then define:
> 
> f <- function(n) {
>  print(ls.str())
>  rep("hello", times = n)
> }
> 
> Now run:
> 
> f(x)
> 
> Instead of getting the expected "object 'x' not found" error, you get:
> 
> n : <missing>[1] "hello"
> 
> It was suggested that I file the issue here as a possible bug.
> 
> 
> Regards,
> 
> Homer
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] issue with promises for time parameter of rep()
Lionel Henry