Displaying 20 results from an estimated 20000 matches similar to: "substitute() on arguments in ellipsis ("dot dot dot")?"
2018 Aug 13
2
substitute() on arguments in ellipsis ("dot dot dot")?
Interestingly,
as.list(substitute(...()))
also works.
On Sun, Aug 12, 2018 at 1:16 PM, Duncan Murdoch
<murdoch.duncan at gmail.com> wrote:
> On 12/08/2018 4:00 PM, Henrik Bengtsson wrote:
>>
>> Hi. For any number of *known* arguments, we can do:
>>
>> one <- function(a) list(a = substitute(a))
>> two <- function(a, b) list(a = substitute(a), b =
2018 Aug 13
1
substitute() on arguments in ellipsis ("dot dot dot")?
Since you're already using bang-bang ;)
library(rlang)
dots1 <- function(...) as.list(substitute(list(...)))[-1L]
dots2 <- function(...) as.list(substitute(...()))
dots3 <- function(...) match.call(expand.dots = FALSE)[["..."]]
dots4 <- function(...) exprs(...)
bench::mark(
dots1(1+2, "a", rnorm(3), stop("bang!")),
dots2(1+2, "a",
2018 Aug 13
0
substitute() on arguments in ellipsis ("dot dot dot")?
Thanks all, this was very helpful. Peter's finding - dots2() below -
is indeed interesting - I'd be curious to learn what goes on there.
The different alternatives perform approximately the same;
dots1 <- function(...) as.list(substitute(list(...)))[-1L]
dots2 <- function(...) as.list(substitute(...()))
dots3 <- function(...) match.call(expand.dots = FALSE)[["..."]]
2014 May 01
3
How to test if an object/argument is "parse tree" - without evaluating it?
This may have been asked before, but is there an elegant way to check
whether an variable/argument passed to a function is a "parse tree"
for an (unevaluated) expression or not, *without* evaluating it if
not?
Currently, I do various rather ad hoc eval()+substitute() tricks for
this that most likely only work under certain circumstances. Ideally,
I'm looking for a isParseTree()
2019 Mar 08
0
Ellipsis and dot-dot-number [Re: Dots are not fixed by make.names()]
Hi
In addition to the inconsistency in make.names(), the text in ?Reserved
seems incomplete:
"Reserved words outside quotes are always parsed to be references to the
objects linked to in the ?Description?, and hence they are not allowed
as syntactic names (see make.names). They **are** allowed as
non-syntactic names, e.g. inside backtick quotes."
`..1` and `...` are allowed for
2020 Oct 06
3
understanding as.list(substitute(...()))
I probably need to be more specific. What confuses me is not the use
of substitute, but the parenthesis after the dots. It clearly works
and I can make guesses as to why but it is definitely not obvious.
The following function gives the same final result but I can
understand what is happening.
dots <- function (...) {
exprs <- substitute(list(...))
as.list(exprs[-1])
}
In the
2007 Mar 20
1
Symbol and Ellipsis problems
Hi Everyone,
When I have a load of functions which have various arguments passed
via the ellipsis argument it keeps on assigning them as symbol making
them unusable to the function. My current work around involves using
do.call but this is rather cumbersome.
Does anyone know why it suddenly changes the types to symbol and if
there is a way to get the actual data pointed to by the symbol? (I
2016 Sep 25
3
withAutoprint({ .... }) ?
>>>>> Henrik Bengtsson <henrik.bengtsson at gmail.com>
>>>>> on Sat, 24 Sep 2016 11:31:49 -0700 writes:
> Martin, did you post your code for withAutoprint() anywhere?
> Building withAutoprint() on top of source() definitely makes sense,
> unless, as Bill says, source() itself could provide the same feature.
I was really mainly asking
2020 Oct 06
0
understanding as.list(substitute(...()))
Hi Tim,
I have also asked a similar question a couple of months ago, and someone
else did the same recently, maybe on r-devel.
We received no "official" response, but Deepayan Sarkar (R Core Team
member) claimed that:
"
There is no documented reason for this to work (AFAIK), so again, I
would guess this is a side-effect of the implementation, and not a API
feature you should
2019 May 30
2
stopifnot
Here is a patch to function 'stopifnot' that adds 'evaluated' argument and makes 'exprs' argument in 'stopifnot' like 'exprs' argument in 'withAutoprint'.
--- stop.R 2019-05-30 14:01:15.282197286 +0000
+++ stop_new.R 2019-05-30 14:01:51.372187466 +0000
@@ -31,7 +31,7 @@
.Internal(stop(call., .makeMessage(..., domain = domain)))
}
2016 May 04
4
Is it possible to retrieve the last error? (not error *message*)
Hi,
at the R prompt, is it possible to retrieve the last error (as in
condition object of class "error")?
I'm not asking for geterrmessage(), which only returns the error
message (as a character string). I'm basically looking for a
.Last.error or .Last.condition, analogously to .Last.value for values,
which can be used when it is "too late" (not possible) to go back
2019 Mar 02
1
stopifnot
A private reply by Martin made me realize that I was wrong about
stopifnot(exprs=TRUE) .
It actually works fine. I apologize. What I tried and was failed was
stopifnot(exprs=T) .
Error in exprs[[1]] : object of type 'symbol' is not subsettable
The shortcut
assert <- function(exprs) stopifnot(exprs = exprs)
mentioned in "Warning" section of the documentation similarly fails
2019 Mar 05
2
stopifnot
Another possible shortcut definition:
assert <- function(exprs)
do.call("stopifnot", list(exprs = substitute(exprs), local = parent.frame()))
After thinking again, I propose to use
??? ? ? stop(simpleError(msg, call = if(p <- sys.parent()) sys.call(p)))
- It seems that the call is the call of the frame where stopifnot(...) is evaluated. Because that is the correct context, I
2020 Oct 06
0
understanding as.list(substitute(...()))
You need to understand what substitute() does -- see ?substitute and/or a
tutorial on "R computing on the language" or similar.
Here is a simple example that may clarify:
> dots <- function(...) as.list(substitute(...()))
> dots(log(foo))
[[1]]
log(foo) ## a call, a language object
> dots2 <- function(...) as.list(...)
> dots2(log(foo))
Error in as.list(...) :
2020 Oct 05
2
understanding as.list(substitute(...()))
Could someone explain what is happening with the ...() of the
following function:
dots <- function(...) as.list(substitute(...()))
I understand what I'm getting as a result but not why. ?dots and
?substitute leave me none the wiser.
regards
Tim
2016 Sep 24
2
withAutoprint({ .... }) ?
>>>>> William Dunlap <wdunlap at tibco.com>
>>>>> on Fri, 2 Sep 2016 08:33:47 -0700 writes:
> Re withAutoprint(), Splus's source() function could take a expression
> (literal or not) in place of a file name or text so it could support
> withAutoprint-like functionality in its GUI. E.g.,
>> source(auto.print=TRUE,
2008 Feb 27
1
Warnings generated by log2()/log10() are really large/takes a long time to display
x <- rnorm(1e6);
y <- log(x); # or logb(x) or log1p(x)
w <- warnings();
print(object.size(w));
## [1] 480
str(w);
$ NaNs produced: language log(x)
- attr(*, "dots")= list()
- attr(*, "class")= chr "warnings"
y <- log2(x); # or log10(x)
w <- warnings();
print(object.size(w));
## [1] 8000536
str(w);
## List of 1
## $ NaNs produced: language
2003 Sep 03
1
Last line in .Rprofile must have newline (PR#4056)
Full_Name: Henrik Bengtsson
Version: R v1.7.1
OS: WinXP Pro, Solaris 9
Submission from: (NULL) (130.235.2.229)
A colleague of mine who is new to R had problems setting up his .Rprofile and we
tracked it down to the following. On both WinXP and Solaris with Rv1.7.1 we
noticed that the *last* line in .Rprofile has to have a *newline* to be
evaluated. For instance, starting R with the following
2019 Feb 27
1
stopifnot
My points:
- The 'withCallingHandlers' construct that is used in current 'stopifnot' code has no effect. Without it, the warning message is the same. The overridden warning is not raised. The original warning stays.
- Overriding call in error and warning to 'cl.i' doesn't always give better outcome. The original call may be "narrower" than 'cl.i'.
I
2002 Aug 06
1
write.table() adds unnecessary spaces to right align integer column
When using write.table() to write data frames the integer columns are padded
with unnecessary spaces (0x20) so that these columns are right align if you
look at them in a text editor. However, I think it is quite a vast of file
size. For instance, I am reading a tab-delimited 4200kb microarray data file
and writing it back verbatim using write.table() and it becomes 5100kb, a
20% increase. Is this