Displaying 20 results from an estimated 10000 matches similar to: "how to manipulate ... within a function"
2008 Dec 19
1
can a function alter the "..." argument and passed the result to another function?
Is there a way a function ('parent', say) can manipulate the ...
argument, and then pass the manipulated value into another function
('child', say) that it calls?
What I'm trying to do is to use some plotting defaults within 'parent'
that are not part of parent's argument list, but to let the use over-
ride these defaults if they choose. A sketch is below.
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
2004 Jan 15
3
Extracting multiple elements from a list
For a long time I've wanted a way to conveniently extract multiple elements
from a list, which [[ doesn't allow. Can anyone suggest an efficient
function to do this? Wouldn't it be a sensible addition to R?
For example,
alist <- list()
alist[[1]] <- list()
alist[[1]]$name <- "first"
alist[[1]]$vec <- 1:4
alist[[2]] <- list()
alist[[2]]$name <-
2004 Sep 14
3
Getting the argument list within a function
Is there a way of getting the argument list of a function from within
that function? For example, something like
f <- function(x, y = 3) {
fargs <- getFunctionArgList()
print(fargs) ## Should be `alist(x, y = 3)'
}
Thanks,
-roger
2003 Nov 13
1
Can't get Sweave syntax highlighting with Emacs
I can't get Emacs to automatically do syntax highlighting of
Sweave files. I have followed Friedrich's suggestion for code
to insert into my .emacs file. The complete section from my .emacs
file is given below. When I load a *.Snw file, font is white until I press
M-x, then the first code and document chunks get highlighted, but not
the rest of the file. Latex and Noweb menus are
2009 Dec 30
1
What am I doing wrong in my loops?
Dear kind list people:
I have the following code:
>hours
[1] "0" "1" "2" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13"
"14" "15"
[16] "16" "17" "18" "19" "20" "21" "22"
2008 Oct 01
2
Bug or feature with finding a list element?
This seems odd. When I try to look up a list element which has a space in
the name using just the first word (i.e. no spaces), it will sometimes
return the element with a space in the name and sometimes it will return
NULL.
Try this:
alist <- list( 'hello'=10, bye=20, 'hello world'=30, 'goodbye world'=40, 'hi
world'=50, 'goodbye foo'=60, 'goodbye
2013 Mar 28
2
how to search a list that contains multiple dissimilar vectors?
Dear All,
This is a simple question, but I'm stumped about the simplest way to search a list object such as the following:
This randomish snippet:
n <- c(round(runif(round(runif(1,1,10),0),1,10),0))
alist <- new("list")
for (i in seq_along(n)) {
alist[[i]] <- c(round(runif(round(runif(1,1,10),0),1,10),0))
}
names(alist) <- sample(letters[1:length(n)])
rm(n);c(alist)
2006 Nov 06
5
alist()
In trying to get NULL members into a list, I found out about alist().
x<-alist()
x$one<-1
x$two<-NULL
but x$two doesn't exist.
It seems, though, that an alist is just a list.
How can one put NULL members into a list?
2009 Nov 19
4
Is there an variant of apply() that does not return anything?
There are a few version of apply() (e.g., lapply(), sapply()). I'm
wondering if there is one that does not return anything but just
silently apply a function to the list argument.
For example, the plot function is applied to each element in 'alist'.
It is redundant to return anything from apply.
apply(alist,function(x){ plot each element of alist})
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
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
2001 Oct 16
4
Assignment of structures on a given environment
Hi,
In order to avoid deep copies by passing large arguments to functions or
returning values, I'm trying to do the assignment of variables in a
given environment. The problem is when I try to assign a structure: a
list for example.
If I have:
ind <- c("a","b")
my idea is doing something like
l <- alist()
l[ind] <- as.list(c(20,40))
in a given
2005 Feb 28
2
Changing function arguments to NULL
I'm trying to build a recursive set of functions that take a set of
arguments, change some of the arguments and recursively call the same
(or different) function.
For example here's a stupid recursive counting function that prints back
all integers from x to 0 (and ignores arguments y and z)
cnt <- function(x, y, z) {
stopifnot(is.numeric(x))
print (x)
recursionFUN <-
2006 Mar 14
3
rails on emacs - need a working .emacs sample
I would like to hear from some one who has ecb, multiple modes with
ruby mode + html mode, rails mode all working together and playing
well.
I had ecb working with Ruby syntax highlighting. That was a no-brainer
since I just had to apt-get them on my Debian Sarge box.
It got a bit more comlex after I got most of the .el files in the articles
http://www.emacswiki.org/cgi-bin/emacs/RubyOnRails
2010 Feb 24
1
Optimise huge data.frame construction
I have data for different items (ID) in a database.
For each ID I have to get:
- Timestamp of the observation (timestamp);
- numerical value (val) that will be my response variable in some kind of model;
- a variable number of variables in a know set (if value for a specific variable is not present in DB it is 0).
To get to the above mentioned values I have to cycle
2009 Mar 22
2
Following progress in a lapply() function
Dear all,
I am processing a very long and complicated list using lapply through a custom function and I would like to generate some sort of progress report. For instance, print a dot on the screen every time 1000 item have been process. Or even better, reporting the percent of the list that have been process every 10%. However, I can't seem to figure out a way to achieve that.
For instance,
2004 Feb 26
2
Sweave and Xemacs on Windows2000?
Hallo!
Trying to configure Xemacs to work with .snw files on windows 2000. Tried to do it how it is described in the FAQ for Sweaves.
When starting xemacs with and Snw file
*ESS* buffer contains hundrets of lines and the few last ones.
(ess-loop-timeout . 500000) (inferior-ess-primary-prompt . ^) (inferior-ess-secondary-prompt . ^) (comint-use-prompt-regexp-instead-of-fields . t)
2007 Oct 16
2
How to speed up multiple for loop over list of data frames
Hi there,
I have a multiple for loop over a list of data frames
for ( i in 1:(N-1) ) {
for ( j in (i+1):N ) {
for ( p in 1:M ) {
v_i[p] = alist[[p]][i,"v"]
v_j[p] = alist[[p]][j,"v"]
}
rho_s = cor(v_i, v_j, method = "spearman")
rho_p = cor(v_i, v_j, method = "pearson"
1999 Mar 29
3
problems with formals and get (PR#151)
With 0.63.3, try
test <- function(){
fn <- function(a) print("hello")
print(is.function(fn))
print(names(formals("fn")))}
test()
if fn is not quoted in the last line of test, it works properly.
test <- function(){
fn <- function() print("hello")
formals(fn) <- alist(a=,b=)
return(fn)}
formals(test())
now try with line 3 of test changed to