Displaying 20 results from an estimated 10000 matches similar to: "converting result of substitute to 'ordidnary' expression"
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
> ##
2009 Mar 09
1
detecting NULL in recursive lists
Dear R-users,
How can I detect a NULL in a recursive list?
For a regular list I could use lapply:
> lapply(list(x=NULL), is.null)
$x
[1] TRUE
However that doesn't work for structures like list(list(x=NULL)). I tried rapply but it treats NULL as a list and discards them:
> rapply(list(a=1, b=list(x=NULL)), is.null)
a
FALSE
Any suggestion?
Thank you for your help,
Vadim
Note:
2005 Mar 08
4
how modify object in parent.env
Hi,
Is it possible to modify an object in the parent.env (as opposed to
re-bind)? Here is what I tried:
> x = 1:3
# try to modify the first element of x from within a new environment
> local(get("x", parent.env(environment()))[1] <- NA)
Error in eval(expr, envir, enclos) : Target of assignment expands to
non-language object
# On the other hand retrieval works just fine
>
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
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?
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
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'),
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 ~
2004 Sep 27
2
passing formula arg to mgcv::gam
Hi,
I have a function, callGam, that fits a gam model to a subset of a dataframe. The argument to callGam is a formula, the subset is determined inside the function itself. My na??ve approach generates and error, see below. I guess this is because 'idx' is loocked up in the environment of 'formula', but I am too ignorant about environments to be able to tell for sure. Could
2003 Sep 03
3
read.table: check.names arg - feature request
Hi,
I thought it would be convenient if the check.names argument to read.table, which currently can only be TRUE/FALSE, could take a function value as well. If the function is supplied it should be used instead of the default make.names.
Here is an example where it can come in handy. I tend to keep my data in coma-separated files with a header line. The header line is prefixed with a comment
2001 Sep 17
3
computational capacity of Linux network
Hi, This is not an R question per ce, but I feel like this is a right
community to ask it.
As a part of our work we run a lot of non-interactive computational jobs. To
increase the throughput we would like to distribute the load over the entire
network and we are looking at Linux network as a platform. Ideally we would
like to be able to submit a job to the network, rather than to a computer,
and
2004 Jun 14
5
mkChar can be interrupted
Hi,
As was discussed earlier in another thread and as documented in R-exts
.Call() should not be interruptible by Ctrl-C. However the following
code, which spends most of its time inside mkChar, turned out to be
interruptible on RH-7.3 R-1.8.1 gcc-2.96:
#include <Rinternals.h>
#include <R.h>
SEXP foo0(const SEXP nSexp) {
int i, n;
SEXP resSexp;
if (!isInteger(nSexp))
2005 May 07
4
how to add method to .Primitive function
Hi,
I tried to write the dim method for the list class, but R doesn't seem
to dispatch to it:
> dim.list = function(x) c(length(x[[1]]), length(x))
> dim(list(1))
NULL
> dim.list(list(1))
[1] 1 1
What is the correct way of registering dim.list with .Primitive("dim")?
Thanks,
Vadim
[[alternative HTML version deleted]]
2004 May 01
5
skip lines on a connection
Hi,
I am looking for an efficient way of skipping big chunks of lines on a
connection (not necessarily at the beginning of the file). One way is to
use read lines, e.g. readLines(1e6), but a) this incurs the overhead of
construction of the return char vector and b) has a (fairly remote)
potential to blow up the memory.
Another way would be to use scan(), e.g.
scan(con, skip=1e6, nmax=0)
2005 Apr 12
5
How allocate STRSXP outside of gc
Hi,
I am trying to figure a way to allocate a string SEXP so that gc() won't
ever collect it.
Here is a little bit of a background. Suppose I want to write a
.Call-callable function that upon each call returns the same value, say
mkChar("foo"):
SEXP getFoo() {
return mkChar("foo");
}
The above implementation doesn't take advantage of the fact that
2004 Mar 17
4
why-s of method dispatching
Hi,
I am having a problem to understand why as.data.frame method doesn't
dispatch properly on my class:
> setClass("Foo", "character")
[1] "Foo"
> as.data.frame(list(foo=new("Foo", .Data="a")))
Error in as.data.frame.default(x[[i]], optional = TRUE) :
can't coerce Foo into a data.frame
I was expecting that this would call
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