search for: myfn

Displaying 20 results from an estimated 34 matches for "myfn".

Did you mean: mfn
2015 Feb 23
5
iterated lapply
...en I evaluate this list of functions by another lapply/sapply, I get an unexpected result: all values coincide. However, when I uncomment the print(), it works as expected. Is this a bug or a feature? conditions <- 1:4 test <- lapply(conditions, function(mycondition){ #print(mycondition) myfn <- function(i) mycondition*i return(myfn) }) sapply(test, function(myfn) myfn(2)) Cheers, Daniel -- Daniel Kaschek Institute of Physics Freiburg University Room 210 Phone: +49 761 2038531
2015 Feb 24
3
iterated lapply
...> another lapply/sapply, I get an unexpected result: all values coincide. > However, when I uncomment the print(), it works as expected. Is this a > bug or a feature? > > conditions <- 1:4 > test <- lapply(conditions, function(mycondition){ > #print(mycondition) > myfn <- function(i) mycondition*i > return(myfn) > }) > > sapply(test, function(myfn) myfn(2)) From: Jeroen Ooms <jeroenooms at gmail.com> > I think it is a bug. If we use substitute to inspect the promise, it > appears the index number is always equal to its last value:...
2008 Jul 17
2
nested calls, variable scope
...r works at the command line, with the call to ns nested within it: > junk2<-lmer(formula=Finished ~ Sex01 + ns(DAT$Age, knots= 74 ) + MinCC + PzC + (1 | NAME ) + (1 | Year), data=myDATonly, family="binomial") But now I want to do this within a function such as the following: > myfn function(myknot=74) { library(lme4) library(splines) cat("myknot=", myknot, "\n") myMER<-lmer(formula=Finished ~ Sex01 + ns(DAT$Age, knots= myknot) + MinCC + PzC + (1 | NAME ) + (1 | Year), data=myDATonly, family="binomial") } &g...
2012 Sep 19
0
[LLVMdev] newbie question on getelementptr
...you for your prompt reply. Unfortunately, I still need more guidance as using the Demo page to generate C++ code didn't result in a global variable being used. Basically, I'm following your advice to use a LoadInst: Value *v = new LoadInst(result, "", theBasicBlock); Function *myfn = cast<Function>(v); I was not sure how I could get a BasicBlock for the LoadInst, so I created a dummy function (which was never called). Casting was successful as myfn->getType()->dump() produced i32 (i32, i32)*. However, I'm getting a "bus error" when trying to run the...
2012 Sep 19
3
[LLVMdev] newbie question on getelementptr
Hi All, I'm new to LLVM and I'm having a coding problem. I'm creating a GlobalVariable that contains a StructType that contains a Function. The function returns i32 and takes two i32's. Here is my code: GlobalVariable* retrieved = module->getGlobalVariable("myGV"); ... Constant* result = ConstantExpr::getGetElementPtr(retrieved, indices); How do I get my Function
2015 Feb 24
0
iterated lapply
...nment interact in this way; the force() function was introduced to help with this. That said, the expression FUN(X[[i]], ...) could be replaced by local({ i <- i list(FUN(X[[i]], ...) }) which would produce the more desirable result > sapply(test, function(myfn) myfn(2)) [1] 2 4 6 8 The C implementation could use this approach, or could rebuild the expression being evaluated at each call to get almost the same semantics. Both would add a little overhead. Some code optimization might reduce the overhead in some instances (e.g. if FUN is a BUILTIN), b...
2002 Apr 26
1
optim or nlm with matrices
...ried to apply optim and nlm functions but I kept receive the following massage: Error in A%*%x1 : non-conformable arguments. The massage appears even the -det() can be calculated and the dimensions are checked. here is my example although there might be no solution for the optimization problem. A=A myfn=function(A){ x=matrix(c(1.8,0),byrow=T) x1=matrix(c(.8,1.8),byrow=T) -det((t(x)-t(x1)%*%A)%*%(x-A%*%x1)) } A=matrix(c(1,.3,2,-1.2),byrow=T,nrow=2) optim(A,myfn) Another question regarding optimization: is there any chance that I can find a function or package that can do a constrained optimization...
2015 Feb 26
3
iterated lapply
...on was introduced to help with this. > > That said, the expression FUN(X[[i]], ...) could be replaced by > > local({ > i <- i > list(FUN(X[[i]], ...) > }) > > which would produce the more desirable result > > > sapply(test, function(myfn) myfn(2)) > [1] 2 4 6 8 > > The C implementation could use this approach, or could rebuild the > expression being evaluated at each call to get almost the same semantics. > Both would add a little overhead. Some code optimization might reduce > the overhead in some instances (...
2015 Feb 24
2
iterated lapply
...ion was introduced to help with this. > > That said, the expression FUN(X[[i]], ...) could be replaced by > > local({ > i <- i > list(FUN(X[[i]], ...) > }) > > which would produce the more desirable result > > > sapply(test, function(myfn) myfn(2)) > [1] 2 4 6 8 > Would the same semantics be applied to parallel::mclapply and friends? sapply(lapply(1:4, function(c){function(i){c*i}}), function(f) f(2)) # [1] 8 8 8 8 sapply(mclapply(1:4, function(c){function(i){c*i}}), function(f) f(2)) # [1] 6 8 6 8 I understand why t...
2011 Dec 12
2
Problems in building a DLL in 64-bit Windows
...ecognized : File format not recognized collect2: ld returned 1 exit status How can I solve this? The problem is with R 2-14.0 and 2-13.0 The complete source code is /* * myfun.c */ #include <stdio.h> #include <R.h> #include <Rinternals.h> #include <R_ext/Rdynload.h> void myfn(double *x){ *x += 1; } The DLL is build like this: R CMD SHLIB -LC:/PROGRA~1/R/R-214~1.0/bin/x64 -lR myfun.c -o myfun64.dll and get the error message above. The R code: # # myfun.R: this works with i386, but not with x64 # dyn.load("myfun64.dll") f <- function(x) {.C("myfn&qu...
2015 Feb 23
0
iterated lapply
...it allows you to have arguments that are never evaluated, because they are never used, or defaults that depend on things that are calculated within the function. Duncan Murdoch > conditions <- 1:4 > test <- lapply(conditions, function(mycondition){ > #print(mycondition) > myfn <- function(i) mycondition*i > return(myfn) > }) > > sapply(test, function(myfn) myfn(2)) > > > > Cheers, > Daniel >
2010 Mar 05
1
How to parse the arguments from a function call and evaluate them in a dataframe?
Hi, I would like to write a function which has the following syntax: myfn <- function(formula, ftime, fstatus, data) { # step 1: obtain terms in `formula' from dataframe `data' # step 2: obtain ftime from `data' # step 3: obtain fstatus from `data' # step 4: do model estimation # step 5: return results } The user would call this function as: myfn(fo...
2000 Oct 06
1
Formulae with factors that have missing values
...("hi",NA,"low","low","hi","low","hi","hi","low",NA,"hi","low","hi","hi","low","hi")) y <- c(1,2,1,2,2,2,1,2,1,1,2,2,1,1,1,2) na.keep <- function(X){X} myfn <- function (formula,data=sys.parent()){ mf <- match.call() mf[[1]] <- as.name("model.frame") if(is.null(mf$na.action)) mf$na.action <- as.name("na.keep") mf <- eval(mf, sys.frame(sys.parent())) Y <- model.extract(mf,response) Terms <...
2015 Feb 26
1
iterated lapply
...e replaced by >> />/ >> />/ local({ >> />/ i <- i >> />/ list(FUN(X[[i]], ...) >> />/ }) >> />/ >> />/ which would produce the more desirable result >> />/ >> />/ > sapply(test, function(myfn) myfn(2)) >> />/ [1] 2 4 6 8 >> />/ >> / >> Would the same semantics be applied to parallel::mclapply and friends? >> >> sapply(lapply(1:4, function(c){function(i){c*i}}), function(f) f(2)) >> >> # [1] 8 8 8 8 >> >> sapply(mcl...
2013 Sep 13
2
[LLVMdev] [lld] Implementing the aliasing feature
...malloc. There will be a malloc seen at build time from libc, and all references to malloc will bind to it. Adding alternate names won’t stop that binding. Yes, thats how ld is behaving, if I have the the function in my .o's, it doesnot override. For example :- #include <stdio.h> int myfn() { return 0; } void __wrap_myfn() { printf("Hello World\n"); } int main() { myfn(); return 0; } $gcc wrap.c -Wl,--wrap,fn $./a.out $ Thanks Shankar Easwaran -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by the Linux Foundation -----------...
2005 Apr 05
1
Fitdistr and likelihood
Hi all, I'm using the function "fitdistr" (library MASS) to fit a distribution to given data. What I have to do further, is getting the log-Likelihood-Value from this estimation. Is there any simple possibility to realize it? Regards, Carsten
2011 Jul 11
4
Save generic plot to file (before rendering to device)
I am looking for a way to save a plot (graphics contents) to a file after the plot has been calculated but before it has been rendered. More specifically, assume that I made a plot that took a very long time to produce, I would like to save this plot to a generic file that I can later, on a different machine, render to either PDF, PNG, SVG using the usual R graphics devices, without recalculating
2011 Jul 11
4
Save generic plot to file (before rendering to device)
I am looking for a way to save a plot (graphics contents) to a file after the plot has been calculated but before it has been rendered. More specifically, assume that I made a plot that took a very long time to produce, I would like to save this plot to a generic file that I can later, on a different machine, render to either PDF, PNG, SVG using the usual R graphics devices, without recalculating
2007 Jan 26
1
bootstrap bca confidence intervals for large number of statistics in one model; library("boot")
...btain BCA CIs for all three regression parameters and for the fitted values at 50 levels of the predictor. set.seed(1234567) x<-runif(150) y<-2/3 + pi * x^2 + runif(length(x))/2 plot(x,y) DAT<-data.frame(x,y) NEWDATA<-data.frame(x=seq(min(x), max(x), length=50)) library('boot') myfn<-function(data, whichrows) { TheseData<-data[whichrows,] thisLM<-lm( y~poly(x,2), data=TheseData) thisFit<-predict(thisLM, newdata=NEWDATA) c( coef(summary(thisLM))[,"Estimate"] , thisFit) } bootObj<-boot( data=DAT, statistic=myfn, R=1000 ) names(bootObj) dim(bootOb...
2008 Jun 03
3
How to solve a non-linear system of equations using R
Dear R-list members, I've had a hard time trying to solve a non-linear system (nls) of equations which structure for the equation i, i=1,...,4, is as follows: f_i(d_1,d_2,d_3,d_4)-k_i(l,m,s) = 0 (1) In the expression above, both f_i and k_i are known functions and l, m and s are known constants. I would like to estimate the vector d=(d_1,d_2,d_3,d_4) which is solution