Displaying 20 results from an estimated 10000 matches similar to: "computing on expressions"
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
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,
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 Mar 21
2
writintg wrappers around save()
Dear R-users,
I am trying to write a wrapper function around save() that will report the file which is being saved to.
So I thought that the followintg would do the trick, but it doesn't. I understand that 'y' is somehow not visible inside save.verbose, but don't know how to fix this.
save.verbose <- function(..., file) {
cat("save.verbose:", file, "\n")
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,
2008 Feb 25
1
how to write dput-able objects
Hi,
One way of doing object-oriented programming in R is to use function environment to hold object's data, see for example
@Article{Rnews:Chambers+Lang:2001a,
author = {John M. Chambers and Duncan Temple Lang},
title = {Object-Oriented Programming in {R}},
journal = {R News},
year = 2001,
volume = 1,
number = 3,
pages = {17--19},
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 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')
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
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
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 Feb 26
1
error loading library
Hi,
I am debugging intermittent crashes of R that seem to happen when multiple R sessions nearly summaltaneously load same dll-based library.
I have R and my libraries installed on a network drive (everything is Windows). The drive is visible from a farm of servers. I have an R script, foo.R, that just loads a dll-based library (to be precise it loads a library that requires a dll-based
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 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'),
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
2007 Dec 17
1
names in Rscript -e
Hi,
I seem to have a problem when passing named parameters to R via Rscript (R2.5.1, bash shell). As soon as I name elements of a list Rscript generates an error.
I will appreciate if someone could point to me a correct way of doing this.
Thanks,
Vadim
## This works
bash-3.2$ Rscript.exe -e 'list(1)'
[[1]]
[1] 1
# and these do not work
bash-3.2$ Rscript.exe -e
2009 Dec 01
1
Adding and Multiplying two Unevaluated Expressions
HI,
As I'm trying to compute Taylor series, I'm having problems in adding and multiplying unevaluated expressions. I searched for a solution but found none.
my Taylor function works fine for evaluating functions as you can see here:
rTaylorVal=function(exp,x0,dx,n) {
ls=list(x=x0)
newexp=eval(exp,ls)
exp0=exp
for (i in 1:n){
exp0=D(exp0,"x")
2007 May 03
2
convert text to exprission good for lm arguments
Hi,
I ran into a problem of converting a text representation of an expression into parsed expression to be further evaluated inside lm ().
> n <- 100
> data <- data.frame(x= rnorm (n), y= rnorm (n))
> data. lm <- lm (y ~ x, data=data)
>
> ## this works
> update(data. lm , subset=x<0)
Call:
lm (formula = y ~ x, data = data, subset = x < 0)