On 13/11/2015 12:53 PM, ALBERTO VIEIRA FERREIRA MONTEIRO wrote:
I have another environment question.
I understand why this works as expected:
f.factory <- function()
{
y <- 2
fname <- paste("plus", y, sep = ".")
f <- function(x) x + y
assign(fname, f, envir = globalenv())
}
f.facto
Make a new environment for each function and populate it with
the variables that your functions require. local() is a convenient
way to do this:
f.factory3 <- function(destinationEnvir = globalenv())
{
for (y in 2:3) {
fname <- paste("plus", y, sep = ".")
f <- local(function(x) x + y, e
I have another environment question.
I understand why this works as expected:
f.factory <- function()
{
y <- 2
fname <- paste("plus", y, sep = ".")
f <- function(x) x + y
assign(fname, f, envir = globalenv())
}
f.factory()
plus.2(2) # 4
and I also understand why this does NOT work:
f.f
I do not understand exactly what you're looking for: "Any way to
rewrite the code.." is pretty vague. Here is _an_ answer, which may
completely miss what you mean, followed by some comments.
y <- 1
f1 <- function(x=y) {
cat("y =", x, "\n")
}
f2 <- function() {
y <- 2
f1()
}
f3 <- functio
On 23/10/2015 11:08 AM, ALBERTO VIEIRA FERREIRA MONTEIRO wrote:
> From the code below:
>
> y <- 1
>
> f1 <- function() {
> cat("y =", y, "\n")
> }
>
> f2 <- function() {
> y <- 2
> f1()
> }
>
> f3 <- function() {
> y <- 3
> f <- f1
> f()
> }
>
> f4 <- function() {
> y <- 4
>
>From the code below:
y <- 1
f1 <- function() {
cat("y =", y, "\n")
}
f2 <- function() {
y <- 2
f1()
}
f3 <- function() {
y <- 3
f <- f1
f()
}
f4 <- function() {
y <- 4
f <- function() { cat("y =", y, "\n") }
f()
}
f1()
f2()
f3()
f4()
Clearly, f1(), f2() and f4() will di
Hello!
Here is yet another question which I strongly suspect has a simple answer.
I build an RcmdrPlugin package and saved my workspace when I came out of R.
For some reason, it save the namespace of the plugin as an environment.
When I load the workspace back in, 2 environments appear,
and
Hello Niels,
Thank you very much! Your solution was exactly what I needed.
(I didn't realize that "formula" has it's own environment - very useful!)
Best,
Tal
Contact
Details:---
Contact me: tal.gal...@gmail.com | 972-52-7275
Hi Tal
On 29/01/11 13.25, Tal Galili wrote:
Hello all,
I came across a behavior of R with environments that I'm not sure what is
causing it.
It involves changing variables that are found through using model.frame on a
formula inside a function.
I wonder if it's a "bug" or a "feature". And in e
Hello all,
I came across a behavior of R with environments that I'm not sure what is
causing it.
It involves changing variables that are found through using model.frame on a
formula inside a function.
I wonder if it's a "bug" or a "feature". And in either case, how it might
be managed.
Here is
Edna Bell wrote:
Hi R users!
I was looking at some of the example code for the "environment"
function. Here it is:
e1 <- new.env(parent = baseenv()) # this one has enclosure package:base.
e2 <- new.env(parent = e1)
assign("a", 3, envir=e1)
ls(e1)
ls(e2)
exists("a", envir=e2) # this succeeds
Hi R users!
I was looking at some of the example code for the "environment"
function. Here it is:
e1 <- new.env(parent = baseenv()) # this one has enclosure package:base.
e2 <- new.env(parent = e1)
assign("a", 3, envir=e1)
ls(e1)
ls(e2)
exists("a", envir=e2) # this succeeds by inheritance
exi
12 matches
Mail list logo