similar to: detecting NULL in recursive lists

Displaying 20 results from an estimated 11000 matches similar to: "detecting NULL in recursive lists"

2010 Jun 26
3
converting result of substitute to 'ordidnary' expression
Dear R users, As substitute() help page points out: Substituting and quoting often causes confusion when the argument is 'expression(...)'. The result is a call to the 'expression' constructor function and needs to be evaluated with 'eval' to give the actual expression object. And indeed I am confused. Consider: > dat <- data.frame(x=1:10,
2010 Jun 26
3
converting result of substitute to 'ordidnary' expression
Dear R users, As substitute() help page points out: Substituting and quoting often causes confusion when the argument is 'expression(...)'. The result is a call to the 'expression' constructor function and needs to be evaluated with 'eval' to give the actual expression object. And indeed I am confused. Consider: > dat <- data.frame(x=1:10,
2009 Jul 21
1
subscript into matrix discards row/column names
Dear R-help, When the result of a matrix subscription degenerates to a scalar the names implied by the dimnames are discarded. > x <- matrix(0, 1, 1, dimnames=list('a', 'x')) ## below I expected result to have names='x', it's not > x[1,] [1] 0 ## below I expected result to have names='a', it's not > x[,1] [1] 0 This is probably a side effect
2010 Oct 15
1
calling browser on error
Dear R-developers, I am trying to figure out a way to call browser() when an error occur, and naturally I want the browser() to be called in the environment of the error. I tried something simple in vain: > f <- function() { x <- 1; stop('ok') } > tryCatch(f(), error=browser()) Called from: tryCatch(f(), error = browser()) ## if browser() was called in the local environment
2010 Jun 26
2
subset arg in subset(). was: converting result of substitute to 'ordidnary' expression
Dear R users, Please disregard my previous post "converting result of substitute to 'ordidnary' expression". The problem I have has nothing to do with substitute. Consider: > dat <- data.frame(x=1:10, y=1:10) > subsetexp <- expression(5<x) > ## this does work > subset(dat, eval(subsetexp)) x y 6 6 6 7 7 7 8 8 8 9 9 9 10 10 10 > ##
2008 Oct 03
2
computing on expressions
Dear R-users, Suppose I have an expression: expr = expression(a>0) and now I want to modify it to expression(a>0 & b>0). The following doesn't work: expr = expression(expr & b>0) What would be a good way of doing this? Thanks, Vadim ________________________________ Note: This email is for the confidential use of the named addressee(s) only and may contain
2008 Nov 28
1
names generated in list indexing
Dear R-devel, When a character vector is used to subscript a list and when some of the subscripts are not present in the list names R returns NULL for those subscripts and generate NA names for each of them: > list(b=1)[c('a','b')] $<NA> <<-- generated name NULL $b [1] 1 Wouldn't it be more intuitive to use the subscript name rather than to generate an NA?
2008 Aug 15
1
stopifnot message mutation
Dear R-users, Could someone please explain why the message printed by function stopifnot2, see below, is different from that of stopifnot itself? Thank you for your help, Vadim > stopifnot2 <- function(...) stopifnot(...) > stopifnot(F) Error: F is not TRUE > stopifnot2(F) Error: ..1 is not TRUE > version _ platform i386-pc-mingw32 arch i386 os
2008 Sep 04
1
lapply(NULL, ...) returns empty list
Dear R-devel, Is there a reason that lapply(NULL, ...) returns the empty list, rather than NULL? It seems intuitive to expect the latter, and rather counterintuitive that lapply(list(), ... ) returns the same value as lapply(NULL, ...). > lapply(list(), function(x) 1) list() > lapply(NULL, function(x) 1) list() > version _ platform i386-pc-mingw32 arch
2008 Aug 08
1
operating on arrays of unknown dimensionality
Dear R-users, I am looking for a way to assign to slices of arrays where dimensionality of the array is not a-priory known. Specifically, I would like to be able to generalize the following example of dimensionality 2 to an arbitrary diminsionality: In this example we create an array x, a smaller array y and then assign y to a slice of x. > dimnmx <- list(c('a','b'),
2008 Aug 20
1
names of return value of median
Dear R-devel, The median() function assigns a name, "NA", to its return value if the return value is NA and the input vector has names, otherwise the names attribute is NULL. This looks strange and inconsistent with the behavior of mean(). This inconsistency becomes a problem when median() is used inside user code that relies on consistent naming convention. Thanks, Vadim > foo
2008 Jul 23
2
shQuote and cat
Dear R-users, It is my understanding that cat(shQuote(a.string)) should print the origintal a.string. Is this right? I am not sure cat() correctly prints strings which are generated by triple-shQuote(): > shQuote(shQuote("a")) [1] "\"\\\"a\\\"\"" > cat(shQuote(shQuote(shQuote("a"))), '\n')
2008 Jul 23
2
shQuote and cat
Dear R-users, It is my understanding that cat(shQuote(a.string)) should print the origintal a.string. Is this right? I am not sure cat() correctly prints strings which are generated by triple-shQuote(): > shQuote(shQuote("a")) [1] "\"\\\"a\\\"\"" > cat(shQuote(shQuote(shQuote("a"))), '\n')
2009 Oct 13
7
lapply() reccursively
Hi all, I was wondering whether it is possible to use the lapply() function to alter the value of the input, something in the spirit of : a1<-runif(100) a2<-function(i){ a1[i]<-a1[i-1]*a1[i];a1[i] } a3<-lapply(2:100,a2) Something akin to a for() loop, but using the lapply() infrastructure. I haven't been able to get rapply() to do this. The reason is that the "real"
2010 Dec 23
2
data frame with nested data frame
Dear R-users, I am somewhat puzzled by how R treats data frames with nested data frames. Below are a couple of examples, maybe someone could help explain what the guiding logic here is. ## construct plain data frame > z <- data.frame(x=1) ## add a data frame member > z$y <- data.frame(a=1,b=2) ## puzzle 1: z is apparently different from a straightforward construction of the
2009 Jul 21
1
bug in approx crashes R
Dear R-devel, The following line crashes R > approx(1, 1, 0, method='const', rule=2, f=0, yleft=NULL, ties='ordered')$y Process R:2 exited abnormally with code 5 at Tue Jul 21 14:18:09 2009 > version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 9.1 year
2009 Mar 13
1
lsfit w/ rank-deficient x
Dear R-devel, It seems that lsfit incorrectly reports coefficients when the input matrix 'x' is rank-deficient, see the example below: ## here values of 'b' and 'c' are incorrectly swapped > x <- cbind(a=rnorm(100), b=0, c=rnorm(100)); y <- rnorm(100); lsfit(x, y)$coef Intercept a b c -0.0227787 0.1042860 -0.1729261 0.0000000 Warning
2011 Mar 14
1
discrepancy between lm and MASS:rlm
Dear R-devel, There seems to be a discrepancy in the order in which lm and rlm evaluate their arguments. This causes rlm to sometimes produce an error where lm is just fine. Here is a little script that illustrate the issue: > library(MASS) > ## create data > n <- 100 > dat <- data.frame(x=rep(c(-1,0,1), n), y=rnorm(3*n)) > > ## call lm, works fine > summary(lm(y ~
2008 Jun 11
7
applying a function recursively
Hi, I have a question about applying a function recursively through a list. Suppose I have a list where the different elements have different levels of recursion: > test.list<-list("I"=list("A"=c("a", "b", "c"), "B"=c("d", "e", "f"), "C"=c("g", "h", "i")), +
2008 Mar 04
1
making array of lists
Dear R Users, Given two vectors, say a = seq(2) and b = seq(3), I want to make an 2*3 array, where (i,j) element is list(a=a[i], b=b[j]). I tried the outer() function but it generates an error message that I don't understand, see below. What do I do wrong? The expan.grid function is not good enough since I need a solution that works when a and b are not atomic, say a=list(list(x=1,