Displaying 20 results from an estimated 20000 matches similar to: "What do you call the value that represents a missing argument?"
2012 Oct 04
2
How to build a list with missing values? What is missing, anyway?
This is tangentially related to Hadley's question.
Suppose I'm building a function programmatically; I have assembled an
expression for the body and I know the names of the arguments it wants
to take.
Suppose I have some convenience function such that writing
make_function(alist(a=, b=), quote(a+b), environment())
is equivalent to writing
function(a,b) a+b
So how do I make the
2009 Oct 01
1
inverse currying
Dear list,
I have the following function,
sugar = function(fun, id = "id"){
ff <- formals(fun)
if( id %in% names(ff))
stop("id is part of args(fun)")
formals(fun) <- c(unlist(ff), alist(id=))
fun
}
which one may use on a function foo,
foo = function(x){
x
}
sugar(foo) # results in the extended closure,
function (x, id)
{
x
}
Its limitation (other
2013 Feb 18
2
quote() vs quote(expr=)
Hi all,
I think there's a small buglet in quote:
str(quote())
# Error in quote() : 0 arguments passed to 'quote' which requires 1
str(quote(expr = ))
# symbol
I bring this up because this seems like the most natural way of
capturing the "missing" symbol with pure R code, compared to
substitute() or bquote() or formals(plot)$x
Hadley
--
Chief Scientist, RStudio
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
> >
2024 Feb 18
1
Capturing Function Arguments
? Sat, 17 Feb 2024 11:15:43 -0700
"Reed A. Cartwright" <racartwright at gmail.com> ?????:
> I'm wrapping a function in R and I want to record all the arguments
> passed to it, including default values and missing values.
This is hard if not impossible to implement for the general case
because the default arguments are evaluated in the environment of the
function as it
2011 Dec 31
4
Base function for flipping matrices
Hi all,
Are there base functions that do the equivalent of this?
fliptb <- function(x) x[nrow(x):1, ]
fliplr <- function(x) x[, nrow(x):1]
Obviously not hard to implement (although it needs some more checks),
just wondering if it had already been implemented.
Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
2011 May 04
4
Recursive objects
Hi all,
Does anyone have a comprehensive list of recursive-type objects in R?
is.recursive defines them as by exclusion: "most types of objects are
regarded as recursive, except for vector types, ?NULL? and symbols
(as given by ?as.name?)." I think this that means recursive objects
are:
* lists
* pairlists
* calls
* expressions
Did I miss anything?
Hadley
--
Assistant
2009 Apr 17
1
cast function in package reshape
Hello R useRs,
I have a function which returns a list of functions :
freq1 <- function(x) {
lev <- unique(x[!is.na(x)])
nlev <- length(lev)
args <- alist(x=)
if (nlev == 1) {
body <- c("{", "sum(!is.na(x))", "}")
f <- function() {}
formals(f) <- as.pairlist(args)
body(f) <- parse(text = body)
namef <-
2011 Oct 18
9
readRDS and saveRDS
Hi all,
Is there any chance that readRDS and saveRDS might one day become
read.rds and write.rds? That would make them more consistent with the
other reading and writing functions.
Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
2011 Sep 21
3
Quelplot
Hi all,
Does anyone have an R implementation of the queplot (K.?M. Goldberg
and B.?Iglewicz. Bivariate extensions of the boxplot. Technometrics,
34(3):pp. 307?320, 1992)? I'm struggling with the estimation of the
asymmetry parameters.
Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
2010 Aug 24
2
Comparing/diffing strings
Hi all,
all.equal is generally very useful when you want to find the
differences between two objects. It breaks down however, when you
have two long strings to compare:
> all.equal(a, b)
[1] "1 string mismatch"
Does any one know of any good text diffing tools implemented in R?
Thanks,
Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice
2018 Jun 08
3
Subsetting the "ROW"s of an object
> On Jun 8, 2018, at 1:49 PM, Hadley Wickham <h.wickham at gmail.com> wrote:
>
> Hmmm, yes, there must be some special case in the C code to avoid
> recycling a length-1 logical vector:
Here is a version that (I think) handles Herve's issue of arrays having one or more 0 dimensions.
subset_ROW <-
function(x,i)
{
dims <- dim(x)
index_list <-
2010 Nov 09
3
How to detect if a vector is FP constant?
Hi all,
What's the equivalent to length(unique(x)) == 1 if want to ignore
small floating point differences? Should I look at diff(range(x)) or
sd(x) or something else? What cut off should I use?
If it helps to be explicit, I'm interested in detecting when a vector
is constant for the purpose of visual display. In other words, if I
rescale x to [0, 1] do I have enough precision to get
2010 Aug 24
3
require is to suggests as what is to imports?
Hi all,
If a package suggests another package in its description, you can
check it at runtime with requires. How do you do check if a package
is available without loading it, if you only want to access one
function in the package namespace.
Thanks,
Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
2011 Apr 13
2
Line plots in base graphics
Am I missing something obvious on how to draw multi-line plots in base graphics?
In ggplot2, I can do:
data(Oxboys, package = "nlme")
library(ggplot2)
qplot(age, height, data = Oxboys, geom = "line", group = Subject)
But in base graphics, the best I can come up with is this:
with(Oxboys, plot(age, height, type = "n"))
lapply(split(Oxboys[c("age",
2011 Aug 16
2
sysdata.rda, namespaces and package dependencies
Hi all,
I'm struggling with accessing a package dataset (munsell.map, stored
in sysdata.rda) when that package is imported, not required. A simple
reproducible example is:
install.packages("munsell")
munsell::mnsl("10B 4/6")
# Error in match(col, munsell.map$name) : object 'munsell.map' not found
library(munsell)
munsell::mnsl("10B 4/6")
# Function
2010 Mar 19
5
Encrypt/decrypt in R
Hi all,
Does any one know of any encryption/decryption algorithms in R? I'm
not looking for anything robust - I want some way of printing output
to the screen that the user can't read immediately, but can decrypt a
little later. The main thing I don't want to the user to see is a
number, so (e.g.) ROT13 isn't appropriate.
Hadley
--
Assistant Professor / Dobelman Family Junior
2025 Jan 08
1
Extracting specific arguments from "..."
That's very nice, Hadley. Simple and clean. Never would have thought of it
myself.
As usual, however, in the course of my churnings, I have a further
complication to add. But first ...
**TO ALL**: Feel free to ignore the following, as I'm just fooling around
here and don't want to waste your time with my stupid stuff.
Anyway, the complication is motivated by the use of formals() or
2011 May 02
2
Using substitute to access the expression related to a promise
Hi all,
The help for delayedAssign suggests that you can use substitute to
access the expression associated with a promise, and the help for
substitute says: "If it is a promise object, i.e., a formal argument
to a function or explicitly created using ?delayedAssign()?, the
expression slot of the promise replaces the symbol.
But this doesn't seem to work:
> a <- 1
> b <- 2
2012 Jul 27
1
Version of substitute that evaluates it's first argument
Hi all,
Does there already exist a version of substitute that evaluates it's
first argument? (i.e. it accepts an already quoted expression). This
seems like something that's pretty handy, but I haven't found any
existing function to do it:
substitute_e <- function(expr, env) {
eval(substitute(substitute(expr, env), list(expr = expr)))
}
f <- quote(x + y + z)
substitute(f,