search for: testfun

Displaying 20 results from an estimated 35 matches for "testfun".

Did you mean: testfunc
2009 Jun 20
2
Special characters in Rd example section will cause errors
Hi (Duncan?), The other day I noticed some characters will cause errors in R CMD CHECK because of parse_Rd(), and AFAIK, these chars include '%', '{' and '}'. For example, note the comments in the example section: %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~% \name{testfun} \Rdversion{1.1} \alias{testfun} \title{ A Test } \description{ A test } \usage{ testfun() } \value{ NULL } \author{ Yihui Xie } \examples{ # special characters in comments # what if a bracket '{' here? } \keyword{ misc } %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~% ## error occurs > tools:::p...
2006 Dec 20
4
R windows crash (PR#9426)
...: Windows Xp Submission from: (NULL) (61.88.57.1) R gui exits without warning when I run a function which has an argument with a default that is not found. This was a result of an error in a function I wrote, but I thought that it should exit more gracefully than it does. Here is an example: testfun <- function(aa=aa) { aa <- lm(y~x,data=aa) return(aa) } testfun() #R then exits. Note that testfun <- function(aa=bb) { aa <- lm(y~x,data=aa) return(aa) } works as it should, giving "object bb not found".
2012 Oct 07
3
get: problem with environments
Dear R users, I am running R-2.15.1 in Linux Slackware64-14.0. Here is my minimal working example: testfun <- function (x) { a <- 0; sapply(X="a", FUN=get, envir=sys.frame(which=x)); } Inside R, that is R called from within a Linux terminal, the following code works: testfun(x=5) print(testfun(x=6)) But within rkward the above code fails and the following works: testfun(x=1) print(tes...
2011 Jul 12
2
foreach not recognizing functions in memory
All, I am not understanding the scoping used in foreach when it is used inside a function. I keep getting "could not find function" errors for functions that are in memory when I try to use foreach within a function call. I have a simple example below. "testFun" is in memory and works when called by foreach directly, but when I place foreach in a function called "helper" and then call helper, foreach cannot find "testFun". Can anyone provide a fix? I hope its just a simple mistake on my part and not a limitation of foreach. >...
2012 Aug 08
1
random number generator with SNOW/ Parallel/ foreach
...indows xp 32bit R). . 1. Suppose I would like to use package *foreach*, can I use current Sys.time as a seed? Although I can get the time up to1e-6 second precesion, the code below dose not work well on a local machine with two cores. ################# library(foreach) library(snow) library(doSNOW) testfun=function(){ options(digits.secs=6) set.seed(slave.seed <- substring(Sys.time(), 21, 26)) a <- rnorm(5,0,1) return(a) } maxkk <- 5 cl <- makeCluster(5, type = "SOCK") registerDoSNOW(cl) results=f...
2015 Feb 18
2
Different serialization of functions in interactive vs. batch mode
...aching also depends on the hash-value of the function that is being cached (calculated using the digest package). I noticed that computations that should already be cached are recomputed when switching from an interactive session to a BATCH session. Therefore, I wrote a test script library(digest) testfun <- function() { return(NULL) } testval <- "testval" print(digest(testfun)) print(serialize(testfun, connection = NULL)) and executed it once using input-redirection from a file (testFile.R) and once copying the code into an interactive R session. The hash-values of the function...
2015 Feb 18
4
Different serialization of functions in interactive vs. batch mode
...y that is. Do you know why in interactive mode the attribute with the srcref is set, but not in batch mode? Thanks! Holger P.S. I attached the output I get when i set the attributes to NULL On Wed, Feb 18, 2015 at 3:04 PM, <luke-tierney at uiowa.edu> wrote: > Add > > attributes(testfun) > > and you will see where the two functions differ. > > luke > > > On Wed, 18 Feb 2015, Holger Hoefling wrote: > >> Hi, >> >> I posted this question to the regular help list, but it seems to be >> this is probably a question that is better addressed...
2013 Jan 14
2
The three-dot question
Dear all, Why does not the three-dot accept arguments from the parent environment? I am just confused with this error, can someone give me a hint? > rm(list=ls()) > testFun <- function(a, ...) + { + if(a){ + print(a) + }else + { + print(b) + } + } > > myTask <- function(a) + { + b <- 3 + testFun(a, b = b) + } > myTask(FALSE) Error in print(b) : object 'b' not found Thanks in advance! F...
2005 Aug 17
4
accesing slots of S4 class in C code
...C code and I cannot get the access to its slots working. The following is a toy example, but even this crashes. In R I have: setClass("pd", representation(data="numeric")) x <- new("pd", data=1:5) test <- function(pd.obj) { res <- .C("TestFun", pd.obj) res} test(x) (Of couse I load the DLL as well.) The corresponding C file has: SEXP TestFun(SEXP pd_obj) { SEXP t=R_NilValue; PROTECT(t = GET_SLOT(pd_obj, install("data"))); UNPROTECT(1); return(t); } What I hope to get as a result is the...
2015 Feb 18
0
Different serialization of functions in interactive vs. batch mode
...ried setting the srcref attribute to NULL, but the hash > value is still different and so is the serialization. So this looks > like it is one difference, but not all of them when source attributes are attached they are attached to calls within the body as well, so > attributes(body(testfun)) $srcref $srcref[[1]] ... > Even if all differences were identified - it still leaves me with > different behavior between interactive and batch-mode, though. I am > curious as to why that is. Do you know why in interactive mode the > attribute with the srcref is set, b...
2009 Sep 16
3
apply function across two variables by mult factors
...output into an organized vector form. I can do this using nested loops but it isn't exactly an optimal approach. Thank you for any and all suggestions. Jon # example data frame testDF<-data.frame( x=rnorm(12), y=rnorm(12), f1=gl(3,4), f2=gl(2,2,12)) # example function [trivial] testFun<-function(x){ X<-abs(x[,1]); Y<-abs(x[,2]); as.numeric( paste(round(X), round(Y), sep='.')) } # apply by factor levels but hard to extract values by(testDF[,1:2], list(testDF$f1, testDF$f2), testFun) # Loop works, but not efficient for large datasets testDF$value<-NA for(i...
2012 Jun 09
1
Applying a function to a column of a data frame
Apologees the novice question. Currently climbing up the learning curve of R. Suppose I have the following function and the data.frame: testfun<-function(x=1,y=2) x+y testframe=data.frame(col1=c(1,2),col2=c(3,4)) When evaluating testfun, I want to use the default value for y (which is 2) and for x, I want to feed (one by one) the values in col2 of testframe. How can I achieve this please? Not having much success with apply() Thanks f...
2012 Jun 10
3
Data.frames can not hold objects...What can be done in the following scenario?
R-Help community, I understand that data.frames can hold elements of type double, string etc but NOT objects (such as a matrix etc). This is not convenient for me in the following situation. I have a function that takes 2 inputs and returns a vector: testfun <- function (x,y) seq(x,y,1) I have a data.frame defined as follows: testframe<-data.frame(xvalues=c(2,3),yvalues=c(4,5)) I would like to apply testfun to every row of testframe and then create a new column in the data.frame which holds the returned vectors as objects. Why do I want this?...
2015 Feb 18
1
Different serialization of functions in interactive vs. batch mode
...ode? >> >> Thanks! >> >> Holger >> >> P.S. I attached the output I get when i set the attributes to NULL >> >> >> On Wed, Feb 18, 2015 at 3:04 PM, <luke-tierney at uiowa.edu> wrote: >> > Add >> > >> > attributes(testfun) >> > >> > and you will see where the two functions differ. >> > >> > luke >> > >> > >> > On Wed, 18 Feb 2015, Holger Hoefling wrote: >> > >> >> Hi, >> >> >> >> I posted this question to the...
2015 Feb 18
0
Different serialization of functions in interactive vs. batch mode
Add attributes(testfun) and you will see where the two functions differ. luke On Wed, 18 Feb 2015, Holger Hoefling wrote: > Hi, > > I posted this question to the regular help list, but it seems to be > this is probably a question that is better addressed on r-devel. Sorry > for the double posting. >...
2015 Feb 18
0
Different serialization of functions in interactive vs. batch mode
...ibute with the srcref is set, but not in batch mode? > > Thanks! > > Holger > > P.S. I attached the output I get when i set the attributes to NULL > > > On Wed, Feb 18, 2015 at 3:04 PM, <luke-tierney at uiowa.edu> wrote: > > Add > > > > attributes(testfun) > > > > and you will see where the two functions differ. > > > > luke > > > > > > On Wed, 18 Feb 2015, Holger Hoefling wrote: > > > >> Hi, > >> > >> I posted this question to the regular help list, but it seems to be > &...
2009 Sep 24
1
how to make a function recognize the name of an object/vector given as argument
Dear guRus, I'd like to learn how to make a function recognize the name of an object/vector given as argument If I have : testFun <- function(x,y) plot(x,y, main=paste("plot of",names(x),"and",names(y)) ) # this just a simple example ... a1 <- 5:8 b1 <- 9:6 testFun(a1,b1) # Returns the plot, but not the names of the objects/vectors given as arguments, # but since 'names()' refers to t...
1997 Jun 06
1
R-beta: nlm
...use the function "nlm" to find the mle. I want to use a generic function for the likelihood which would require me to use both the parameters and the data as arguments. But nlm requires the function to have only the parameters as arguments for this function (see example below). > testfun <- function(x,y) sum((x-y)^2) # x - parameters, y - data > nlm(tfun,0) Error: Argument "y" is missing, with no default Thus the problem I have is as follows: llkfun -- generic function to calculate the likelihood for given data and parameters mlefun -- f...
2004 Apr 08
1
Why are Split and Tapply so slow with named vectors, why is a for loop faster than mapply
...(actTime, zoneNames, chainId)) [1] 8.04 0.00 9.03 NA NA However if I rewrite the function to use mapply instead of a for loop, it again takes a long (undetermined) amount of time to complete. Here are the results for just 5000 and 10000 records. You can see that there is a scaling issue: > testfun <- function(dataVector, nameVector, factorVector){ + dataList <- split(dataVector, factorVector) + nameList <- split(nameVector, factorVector) + nameFun <- function(x, xNames){ + names(x) <- xNames + x + } + mapply(nameFun, dataList, nameList,...
2011 Apr 13
3
predict()
Hi, I am experimenting with the function predict() in two versions of R and the R extension package "survival". library(survival) set.seed(123) testdat=data.frame(otime=rexp(10),event=rep(0:1,each=5),x=rnorm(10)) testfm=as.formula('Surv(otime,event)~x') testfun=function(dat,fm) { predict(coxph(fm,data=dat),type='lp',newdata=dat) } # Under R 2.11.1 and survival_2.35-8 testfun(testdat,testfm) > testfun(testdat,testfm) [,1] 1 -0.34786190 2 0.53622182 3 0.07861553 4 0.10030148 5 -0.05329258 6 -0.40619876 7 0.83422564...