Skip to content

how to start local scope?

3 messages · Tamas K Papp, Roger D. Peng, Duncan Murdoch

#
How can I start a local scope inside an R function?  Eg in
Error: object "b" not found
+   {
+     b <- 1
+   }
+   b+2
+ }
[1] 3

I would like f() to report an error, not finding b.  I am thinking
about something like let in Scheme/Lisp.

Thanks,

Tamas
#
Try

f <- function() {
	local({
		b <- 1
	})
	b + 2
}
Tamas K Papp wrote:

  
    
#
On 7/27/2006 8:16 AM, Tamas K Papp wrote:
The local() function does this:

 > f <- function() {
+   local({ b <- 1 })
+   b + 2
+ }
 > f()
Error in f() : object "b" not found