similar to: function environment

Displaying 20 results from an estimated 11000 matches similar to: "function environment"

2006 Aug 16
1
Problem with the special argument '...' within a function
I'm not sure if this is what you want, but simply add ... to the list of arguments for fun1 and fun2 would eliminate the error. Andy From: Hans-Joerg Bibiko > > Dear all, > > I wrote some functions using the special argument '...'. OK, it works. > > But if I call such a function which also called such a > function, then I get an error message about unused
2010 Aug 11
2
storing the results of an apply call
Hi R-users, I have a function (myfun) that I want to apply to the rows of a matrix. Basically, "myfun" takes the values from the matrix ("exp.des"), which represent the different combinations of my experimental design, and pass them as arguments to some other functions (fun1 and fun2). As I want to replicate the results of fun1 and fun2 a certain number of time (e.g. 5), I
2006 Jun 26
2
reshaping data.frame question
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Dear R-helpers, my data.frame is of the form x <- data.frame( f=gl(4,3), X=rep(0:2,4), p=c(.1,.2,.3)) x f X p 1 1 0 0.1 2 1 1 0.2 3 1 2 0.3 4 2 0 0.1 5 2 1 0.2 6 2 2 0.3 7 3 0 0.1 8 3 1 0.2 9 3 2 0.3 10 4 0 0.1 11 4 1 0.2 12 4 2 0.3 which tabulates some values p(X) for several factors f. Now I want to put it in "wide"
2006 Aug 09
3
objects and environments
Dear list, I have two functions created in the same environment, fun1 and fun2. fun2 is called by fun1, but fun2 should use an object which is created in fun1 fun1 <- function(x) { ifelse(somecondition, bb <- "o", bb <- "*") ## mymatrix is created, then myresult <- apply(mymatrix, 1, fun2) } fun2 <- function(idx) { if (bb == "o) { #
2013 Nov 05
2
multi
[[1]]              [,1]      [,2] [1,]  0.003632559 0.2190629 [2,] -2.090772847 0.2190629 [[2]]             [,1]       [,2] [1,] 0.004278991 0.04337005 [2,] 0.190723602 0.04337005 [[3]]            [,1]        [,2] [1,] 0.01237827 -0.01544811 [2,] 0.06452200 -0.01544811 g<-c(1,2,3) function(g,hessianList){    for(i in 1:3){          ft1<-g[2]*hessianList[[2]]          ft2<-sum(ft1)   
2007 Jan 09
4
A question about R environment
Hi all, I created environment "mytoolbox" by : mytoolbox <- new.env(parent=baseenv()) Is there anyway I put it in the search path ? If you need some background : In a project, I often write some small functions, and load them into my workspace directly, so when I list the objects with ls(), it looks pretty messy. So I am wondering if it is possible to creat an
2005 Nov 24
2
what's the meaning of these in R-lang?
In this case the environment contains the variables local to the function, and its enclosure is the environment of the enclosing function.(R-lang:p11) I want to know if the "enclosing function" means the closure of the function? for example ,if I call function mean(),and the create an environment,say e1,then the enclosure of e1 is the namespace of base package? Right? Thank you!
2015 Dec 10
6
How do I reliably and efficiently hash a function?
I?ve got the following scenario: I need to store information about an R function, and retrieve it at a later point. In other programming languages I?d implement this using a dictionary with the functions as keys. In R, I?d usually use `attr(f, 'some-name')`. However, for my purposes I do not want to use `attr` because the information that I want to store is an implementation detail that
2011 Jul 25
1
do.call in "with" construction
Dear all, I'd appreciate any help to rectify what must be a misconception of mine how environments work: ########################## myEnv <- new.env() myEnv$a.env <- 1 myEnv$symbols.env <- "a.env" a.global <- 2 symbols.global <- "a.global" myFun <- function(symbols){do.call("print", lapply(symbols, FUN=as.name))} do.call("myFun",
2018 Nov 29
4
Unexpected argument-matching when some are missing
When trying out some variations with `[.data.frame` I noticed some (to me) odd behaviour, which I found out has nothing to do with `[.data.frame`, but rather with the way arguments are matched, when mixing named/unnamed and missing/non-missing arguments. Consider the following example: myfun <- function(x,y,z) { ? print(match.call()) ? cat('x=',if(missing(x)) 'missing'
2020 May 12
4
S3 method dispatch for methods in local environments
Dear All, In R 3.6.3 (and earlier), method dispatch used to work for methods stored in local environments that are attached to the search path. For example: myfun <- function(y) { out <- list(y=y) class(out) <- "myclass" return(out) } print.myclass <- function(x, ...) print(formatC(x$y, format="f", digits=5)) myfun(1:4) # prints: [1]
2020 May 02
1
issues with environment handling in model.frame()
Dear all, model.frame behaves in a way I don't expect when both its formula and subset argument are passed through a function call. This works as expected: model.frame(~wool, warpbreaks, breaks < 15) #> wool #> 14 A #> 23 A #> 29 B #> 50 B fun1 <- function(y) model.frame(~wool, warpbreaks, y) fun1(with(warpbreaks, breaks < 15)) #> wool #> 14
2006 Mar 25
4
object size vs. file size
Hi, There is rather large discrepancy in the size of the object as it lives in R and the size of the object when it is written to the disk. The object in question is an S4 of a homemade class "sa". I first call a function that writes a list of these objects to a file called "data.RData". The size of this file is 14,411 KB. I would assume on average then, that each list
2023 Aug 03
3
feature request: optim() iteration of functions that return multiple values
Dear all, I have used optim a lot in contexts where it would useful to be able to iterate function myfun that, in addition to the primary objective to be minimized ('minimize.me'), could return other values such as alternative metrics of the minimization, informative intermediate values from the calculations, etc. myfun <- function() { ... return(list(minimize.me = minimize.me, R2 =
2006 Jul 12
2
plot.ts panel function
How can I set the ylim in individual panels of a "multiple" plot.ts? The panels are all scaled to fully fit the series inside. But I need specific scales, and colors .... Here is an example: plot.ts(cbind(1:10,1:10/10),ylim=c(0,3)) # ylim has no effect Can someone more knowledgable please explain how to use the panel= option correctly, thanks! Cheers, m
2006 Nov 29
4
rm() deletes 'c' if c('a','b') is the argument (PR#9399)
Full_Name: Lixin Han Version: 2.4.0 OS: Windows 2000 Submission from: (NULL) (155.94.110.222) A character vector c('a','b') is supplied to rm(). As a result, 'c' is deleted unintentionally. > a <- 1:5 > b <- 'abc' > c <- letters > ls() [1] "a" "b" "c" > rm(c('a','b')) > ls() character(0)
2009 Feb 03
5
Large file size while persisting rpart model to disk
I am using rpart to build a model for later predictions. To save the prediction across restarts and share the data across nodes I have been using "save" to persist the result of rpart to a file and "load" it later. But the saved size was becoming unusually large (even with binary, compressed mode). The size was also proportional to the amount of data that was used to create the
2014 Jun 16
1
model.frame and parent environment
Someone has reported a problem with predict.coxph that I can't seem to solve. The underlying issue is with model.frame.coxph; the same issue is also found in lm so I'll use that for the example. -------------------------- > test <- data.frame(y = 1:10 + runif(10), x=1:10) > myfun <- function(formula, nd) { fit <- lm(formula, data=nd, model=FALSE)
2011 Apr 07
2
Two functions as parametrs of a function.
Hi R users: I'm trying to make a function where two of the parameters are functions, but I don't know how to put each set of parameters for each function. What am I missing? I try this code: f2<-function(n=2,nsim=100,fun1=rnorm,par1=list(),fun2=rnorm,par2=list()){ force(fun1) force(fun2) force(n) p1<-unlist(par1) p2<-unlist(par2) force(p1) force(p2)
2012 Nov 17
3
transform input argument (matrix) of function
Dear list!   I would like to write a function to transform matrix, which is input argument of a written function. It is easy with new matrix (see below), but my idea is to transform input argument (matrix) of function without any additional matrixes. Here is an example: fun1 <- function(xy) { xy <- cbind(xy[,1], xy[,2], xy[,1] + xy[,2]) return(xy) }   df1 <- matrix(c(1,2,3,1,2,3), ncol =