similar to: Assignment of structures on a given environment

Displaying 20 results from an estimated 10000 matches similar to: "Assignment of structures on a given environment"

2001 Oct 17
0
Assignment of structures on a given environment]
Robert Gentleman wrote: > On Tue, Oct 16, 2001 at 04:40:34PM +0100, Rita Ribeiro wrote: > > Hi, > > > > In order to avoid deep copies by passing large arguments to functions or > > > > returning values, I'm trying to do the assignment of variables in a > > given environment. The problem is when I try to assign a structure: a > > list for example.
2020 Jun 01
1
eval and Calling Frames
I ran into an interesting issue with `evalq` (and also `eval(quote(...))`): ???? f <- function() { ?????? list( ???????? sys.parent(1), ???????? evalq(sys.parent(1)), ???????? evalq((function() sys.parent(2))()),? # add an anon fun layer ???????? evalq((function() sys.parent(1))()) ?????? ) ???? } ???? res <- f() ???? str(res) ???? ## List of 4 ???? ##? $ : int 0???????? # sys.parent(1)
2015 Jul 15
2
bquote/evalq behavior changed in R-3.2.1
On Jul 15, 2015, at 12:51 PM, William Dunlap wrote: > I think rapply() was changed to act like lapply() in this respect. > When I looked at the source of the difference, it was that typeof() returned 'language' in 3.2.1, while it returned 'list' in the earlier version of R. The first check in rapply's code in both version was: if (typeof(object) != "list")
2001 Oct 09
3
find indices of nonzero elements
Hi, Is there a function func(x) where x is an array such that it returns a list of the indices of all non-zero elements of the array? for example: a: 1 0 0 0 0 1 0 1 0 func(a) returns two vectors r and c: r c 1 1 2 3 3 2 daver +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |David Richmond It works on a | + Dept. of Sociology complex scientific
2015 Jul 15
2
bquote/evalq behavior changed in R-3.2.1
David, If you are referring to the solution that would be: rapply(list(test), eval, envir = fenv) I thought I explained in the question that the above code does not work. It does not throw an error, but the behavior is no different (at least in the output or result). Using the above code still results in the x object not being stored in fenv on 3.1.2. Dayne On Wed, Jul 15, 2015 at 4:40 PM,
2015 Jul 15
3
bquote/evalq behavior changed in R-3.2.1
In 3.1.2 eval does not store the result of the bquote-generated call in the given environment. Interestingly, in 3.2.1 eval does store the result of the bquote-generated call in the given environment. In other words if I run the given example with eval rather than evalq, on 3.1.2 "x" is never stored in "fenv," but it is when I run the same code on 3.2.1. However, the given
2004 Jan 15
3
Extracting multiple elements from a list
For a long time I've wanted a way to conveniently extract multiple elements from a list, which [[ doesn't allow. Can anyone suggest an efficient function to do this? Wouldn't it be a sensible addition to R? For example, alist <- list() alist[[1]] <- list() alist[[1]]$name <- "first" alist[[1]]$vec <- 1:4 alist[[2]] <- list() alist[[2]]$name <-
2007 May 27
2
Question about "evalq"
The help page of eval says: The 'evalq' form is equivalent to 'eval(quote(expr), ...)'. But the following is not equivalent. Can anyone give me some explaination? Thanks very much. > f1 <- function(x,digits=5) lapply(x, f2) > f2 <- function(x) eval(quote(print(x+1,digits=digits)),list(x=x),parent.frame(2)) > f1(list(x1=1)) [1] 2 $x1 [1] 2 > > f1 <-
2015 Jul 15
3
bquote/evalq behavior changed in R-3.2.1
Hello, I upgraded from 3.1.2 to 3.2.1 and am receiving errors on code that worked as I intended previously. Briefly, I am using bquote to generate expressions to modify data.table objects within a function, so I need the changes to actually be stored in the given environment. Previously, I used code like the following: test <- list(bquote(x <- 10)) fenv <- environment() rapply(test,
2009 Jan 28
1
evaluation revisited
I'm still going over old emails and trying to get my head around evaluation so I'm persistent if nothing else. A while back , an expert sent me below as an exercise in understanding and I only got around to it tonight. I understand some of the output but not all of it and I put "Why not Zero ?" next to the ones that I don't understand based on my reading of the various
2003 Nov 13
1
Can't get Sweave syntax highlighting with Emacs
I can't get Emacs to automatically do syntax highlighting of Sweave files. I have followed Friedrich's suggestion for code to insert into my .emacs file. The complete section from my .emacs file is given below. When I load a *.Snw file, font is white until I press M-x, then the first code and document chunks get highlighted, but not the rest of the file. Latex and Noweb menus are
2002 Sep 04
3
strange things with eval and parent frames
Dear mailing list, I have found some strange behaviour which I think relates to parent frames and eval. Can anyone explain what's going on here? First example: > test.parent.funcs_ function() { outer.var_ 5 subfunc1_ function() substitute( outer.var, envir=parent.frame()) print( subfunc1()) subfunc2b_ function() eval( quote( outer.var), envir=parent.frame()) print(
2009 Dec 30
1
What am I doing wrong in my loops?
Dear kind list people: I have the following code: >hours [1] "0" "1" "2" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15" [16] "16" "17" "18" "19" "20" "21" "22"
2008 Oct 01
2
Bug or feature with finding a list element?
This seems odd. When I try to look up a list element which has a space in the name using just the first word (i.e. no spaces), it will sometimes return the element with a space in the name and sometimes it will return NULL. Try this: alist <- list( 'hello'=10, bye=20, 'hello world'=30, 'goodbye world'=40, 'hi world'=50, 'goodbye foo'=60, 'goodbye
2013 Mar 28
2
how to search a list that contains multiple dissimilar vectors?
Dear All, This is a simple question, but I'm stumped about the simplest way to search a list object such as the following: This randomish snippet: n <- c(round(runif(round(runif(1,1,10),0),1,10),0)) alist <- new("list") for (i in seq_along(n)) { alist[[i]] <- c(round(runif(round(runif(1,1,10),0),1,10),0)) } names(alist) <- sample(letters[1:length(n)]) rm(n);c(alist)
2006 Nov 06
5
alist()
In trying to get NULL members into a list, I found out about alist(). x<-alist() x$one<-1 x$two<-NULL but x$two doesn't exist. It seems, though, that an alist is just a list. How can one put NULL members into a list?
2009 Nov 19
4
Is there an variant of apply() that does not return anything?
There are a few version of apply() (e.g., lapply(), sapply()). I'm wondering if there is one that does not return anything but just silently apply a function to the list argument. For example, the plot function is applied to each element in 'alist'. It is redundant to return anything from apply. apply(alist,function(x){ plot each element of alist})
2009 Oct 01
1
inverse currying
Dear list, I have the following function, sugar = function(fun, id = "id"){ ff <- formals(fun) if( id %in% names(ff)) stop("id is part of args(fun)") formals(fun) <- c(unlist(ff), alist(id=)) fun } which one may use on a function foo, foo = function(x){ x } sugar(foo) # results in the extended closure, function (x, id) { x } Its limitation (other
2007 Jun 08
1
evaluating variables in the context of a data frame
Given > D = data.frame(o=gl(2,1,4)) this works as I expected: > evalq(o, D) [1] 1 2 1 2 Levels: 1 2 but neither of these does: > f <- function(x, dat) evalq(x, dat) > f(o, D) Error in eval(expr, envir, enclos) : object "o" not found > g <- function(x, dat) eval(x, dat) > g(o, D) Error in eval(x, dat) : object "o" not found What am I doing wrong?
2007 May 18
1
subset arg in (modified) evalq
Hi, When using evalq to evaluate expressions within a say data.frame context I often wish there was a 'subset' argument, much like in lm() or any ather advanced regression model. I would be grateful for a tip how to do this. Here is an illustration of what I want: n <- 100 data <- data.frame(x=rnorm(n), y=rnorm(y), z=rnorm(z)) # this works evalq({ i <- 0<x;