Displaying 20 results from an estimated 30000 matches similar to: "on.exit() & sys.on.exit(): Calling them via eval() does not work as hoped"
2017 Aug 04
2
Why is as.function() slower than eval(call("function"())?
(Apologies if this is better suited for R-help.)
On my system (macOS Sierra, late 2014 MacBook Pro; R 3.4.1, Homebrew build), I found that it is faster to construct a function using eval(call("function", ...)) than using as.function(list(...)). Example:
make_fn_1 <- function(a, b) eval(call("function", a, b), env = parent.frame())
make_fn_2 <- function(a, b)
2010 Feb 19
2
What is the difference between expression and quote when used with eval()?
I made the following example to see what are the difference between
expression and quote. But I don't see any difference when they are
used with eval()? Could somebody let me know what the difference is
between expression and quote?
expr=expression(2*3)
quo=quote(2*3)
eval(expr)
str(expr)
class(expr)
typeof(expr)
mode(expr)
attributes(expr)
eval(quo)
str(quo)
class(quo)
typeof(quo)
2016 Oct 19
2
How to assign NULL value to pairlist element while keeping it a pairlist?
On Sat, Oct 15, 2016 at 2:00 AM, Martin Maechler
<maechler at stat.math.ethz.ch> wrote:
>>>>>> Michael Lawrence <lawrence.michael at gene.com>
>>>>>> on Wed, 12 Oct 2016 15:21:13 -0700 writes:
>
> > Thanks, this was what I expected. There is a desire to
> > eliminate the usage of pairlist from user code, which
> >
2010 Feb 09
1
The default argument 'envir' of eval()
In ?eval, it says
? ? ... ?If ?envir? is not
? ? specified, then the default is ?parent.frame()? (the environment
? ? where the call to ?eval? was made).
I tried the following example with "eval(expr)" ?and "eval(expr,
parent.frame())" in f(). The results are different, which are not
consistent with the help. Could somebody let know whether I
misunderstand the help? Or there
2015 Feb 09
1
WISH: eval() to preserve the "visibility" (now value is always visible)
Sorry to intervene.
Argument passed to 'eval' is evaluated first.
So,
eval(x <- 2)
is effectively like
{ x <- 2; eval(2) } ,
which is effectively
{ x <- 2; 2 } .
The result is visible.
eval(expression(x <- 2))
or
eval(quote(x <- 2))
or
evalq(x <- 2)
gives the same effect as
x <- 2 .
The result is invisible.
In function 'eval2',
res <-
2009 Sep 19
3
eval(expr) without printing to screen?
Hi,
I have a script which I source, which evaluates a changing expression
call hundreds of times. It works, but it prints to screen each time,
which is annoying. There must be simple way to suppress this, or to use
a slightly different set of commands, which will be obvious to those
wiser than I...
Here is a simpler mockup which shows the issue:
x = data.frame(rbind(c(1,2,3),c(1,2,3)))
2006 Dec 18
3
turning expression object to function
Dear all,
I have the following problem.
Given an expression object 'expr' containing a certain set of symbols
(say 'a', 'b', 'c'), I would like to translate the expression object
in an R function of, say, 'a', programmatically. Here an example of
what I mean.
Given:
> expr <- expression(a+b+c)
a call like:
> asFunctionOf(expr, 'a',
2007 Dec 22
2
Understanding eval
After many hours of debugging code, I came to the conclusion that I
have a fundamental misunderstanding regarding eval, and hope that
someone here can explain to me, why the following code acts as it does:
foo <- function(expr) {
eval(substitute(expr), envir=list(a=5), enclos=parent.frame())
}
bar <- function(er) {
foo(er)
}
> foo(a)
[1] 5
> bar(a)
Error in eval(expr,
2013 Mar 19
1
source, sys.source and error line numbers
Hi,
is there a way to retrieve the line number of where en error occurred when
sourcing a file in a tryCatch statement? Is it stored somewhere accessible?
It is not found in the error object.
Consider the following code/output and note the difference in the traceback
between source (has line number) and sys.source (has no line number).
Thank you,
Renaud
########
# code
########
codefile <-
2010 Sep 21
3
Error in eval(expr, envir, enclos)
I am absolutely new to R and I am aware of only a few basic command lines. I
was running a robust regression in R, using the following command line
library (MASS)
rfdmodel1 <- rlm (TotalEmployment_2004 ~ MISSISSIPPI + LOUISIANA +
TotalEmployment_2000 + PCWhitePop_2004 + UnemploymentRate_2004 +
PCUrbanPop2000 + PCPeopleWithACollegeDegree_2000 +
PCPopulation.of.or.over.65.years.of.age_2004)
2007 Nov 13
1
`eval' and environment question
my understanding of `eval' behaviour is obviously
incomplete.
my question: usually `eval(expr)' and `eval(expr,
envir=parent.frame())' should be identical. why does the
last `eval' (yielding `r3') in this code _not_ evaluate in
the local environment of function `f' but rather in the
global environment (if `f' is called from there)?
2011 Mar 23
2
) Error in eval(expr, envir, enclos) : object '' not found
> datafilename="E:/my documents/r/sex/bysex1.csv"
> data.sex=read.table(datafilename,header=T)
> data.sex
y.sex.age.region.c.n
1 1980,F,A,N,-18.15,13.61
2 1980,F,A,N,-18.61,13.04
3 1980,F,A,N,-18.81,12.32
4 1990,F,A,N,-21.12,11.7
5 1990,F,A,N,-20.77,11.58
6 1990,F,A,N,-21.6,13.34
7 1990,F,A,N,-21.78,12.6
> model.anova<-aov(c~age*sex,data=data.sex)
From THE R BOOK -> Warning: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm!
2010 Mar 30
3
From THE R BOOK -> Warning: In eval(expr, envir, enclos) : non-integer #successes in a binomial glm!
Dear friends,
I am testing glm as at page 514/515 of THE R BOOK by M.Crawley, that is
on proportion data.
I use glm(y~x1+,family=binomial)
y is a proportion in (0,1), and x is a real number.
I get the error:
In eval(expr, envir, enclos) : non-integer #successes in a binomial glm!
But that is exactly what was suggested in the book, where there is no
mention of a similar warning. Where am I
2013 Jun 24
0
sys.source() does not provide the parsing info to eval()
Hello,
It seems that the parsing information attached to expressions parsed by the
parse() function when keep.source=TRUE is not provided to the eval()
function.
Please consider this code:
path <- tempfile()
code <- '(function() print( str( sys.calls() ) ))()'
writeLines(code, path)
sys.source(path, envir=globalenv(), keep.source=TRUE)
> OUTPUT:
Dotted pair list of 4
$ :
2015 Feb 07
1
WISH: eval() to preserve the "visibility" (now value is always visible)
Would it be possible to have the value of eval() preserve the
"visibility" of the value of the expression?
"PROBLEM":
# Invisible
> x <- 1
# Visible
> eval(x <- 2)
[1] 2
"TROUBLESHOOTING":
> withVisible(x <- 1)
$value
[1] 1
$visible
[1] FALSE
> withVisible(eval(x <- 2))
$value
[1] 2
$visible
[1] TRUE
WORKAROUND:
eval2 <-
2001 Jul 19
1
bug in eval
Is this a bug ?
> foo <- function(a, ...)
+ {
+ tl <- substitute(list(a=a))
+
+ ## the foll two should give the same results
+ ## according to defaults for eval
+
+ print(eval(tl ))
+ print(eval(tl, parent.frame()))
+ }
>
>
> foo1 <- function(...)
+ {
+ foo(...)
+ }
>
> test <- function(a = 6)
+ {
+ foo1(a = a)
+ }
>
>
2008 Feb 13
1
stumped by eval
In the following example, the inner evaluation pulls in the global value
of subset (a function) rather than the one I thought I was passing in (a
vector). Can anyone help me understand what's going on, and what I need
to do to fix the problem?
f0 <- function(formula, data,
subset, na.action
)
{
f1(formula, data,
subset,
2012 May 15
1
Error in eval(expr, envir, enclos) : object 'Rayos' not found???
Hi R-listers,
I am trying to make a trellis boxplot with the HSuccess (y-axis) in each
Rayos (beach sections) (x-axis), for each Aeventexhumed (A, B, C) - nesting
event. I am not able to do so and keep receiving:
Error in eval(expr, envir, enclos) : object 'Rayos' not found
Please advise,
Jean
require(plyr)
resp <- read.csv("ABC Arribada R File Dec 12 Jean
2001 Jan 10
1
eval() bug in plot.formula() ?
I don't have time now to investigate myself,
and I'm not feeling like deciding myself if the following is a bug:
myplot <- function(dat, cex = 1.2, ...) {
if(!is.data.frame(dat <- as.data.frame(dat)))
stop("`dat' must be a data.frame")
if(any(is.na(match(c("x","y"), names(dat)))))
stop("`dat' must have a `x' and a
2009 Apr 02
2
actual argument matching does not conform to the definition (PR#13634)
Full_Name: Wacek Kusnierczyk
Version: 2.10.0 r48269
OS: Ubuntu 8.04 Linux 32 bit
Submission from: (NULL) (129.241.199.164)
In the following example (and many other cases):
quote(a=1)
# 1
the argument matching is apparently incorrect wrt. the documentation (The R
Language Definition, v 2.8.1, sec. 4.3.2, p. 23), which specifies the following
algorithm for argument matching:
1. Attempt to