Displaying 20 results from an estimated 7000 matches similar to: "do.call in "with" construction"
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]
2008 Jan 28
1
package.skeleton from within function: objects not found
Hi all,
I ran into a strange error: I am trying to create a package skeleton for a
new source package from within a function. Objects that are created in this
function are to be included in my package, but for some reason, I get an
error message saying that these objects cannot be found.
Here is the code:
######
myfun <- function(pkgName,x){
myenv <- new.env()
apply(x, 1,
2012 Jul 02
2
Constructing a list using a function...
Hi All
I have a dataframe:
myframe<-data.frame(ID=c("first","second"),x=c(1,2),y=c(3,4))
And I have a function myfun:
myfun<-function(x,y) x+y
I would like to write a function myfun2 that takes myframe and myfun
as parameters and returns a list as below:
mylist
$first
[1] 4
$second
[2] 6
Could you please help me with this? Doesn't seem like the
2011 Jul 23
1
call a function with explicitly not setting an argument
Is there a way to call a function, and explicitly set an argument to 'not
specified'? My situation is the following. I have a function which passes on
most of its arguments to another function. The second function, myfun2,
serializes all arguments and is out of my control.
myfun <- function(...){
return(myfun2(...));
}
now, the value for arguments of myfun are stored in variables.
2006 Jul 06
2
use of apply in a data frame on a row by row basis
Hello all,
I'm trying to use the apply function on a data frame,
by applying a function that takes a one row data.frame as argument .
Here's the example :
myfun = function(x) paste(x$f1 , x$f2)
df = data.frame(f1 = c(1,4,10),f2 = "hello")
apply(df,1,myfun) ==> Does not work (I get "character(0)" )
Though : myfun(df[1,]) works,
and myfun(df) works as well.
So if
2017 Jun 18
3
R_using non linear regression with constraints
I am not as expert as John, but I thought it worth pointing out that the
variable substitution technique gives up one set of constraints for
another (b=0 in this case). I also find that plots help me see what is
going on, so here is my reproducible example (note inclusion of library
calls for completeness). Note that NONE of the optimizers mentioned so far
appear to be finding the true best
2017 Jun 18
0
R_using non linear regression with constraints
I ran the following script. I satisfied the constraint by
making a*b a single parameter, which isn't always possible.
I also ran nlxb() from nlsr package, and this gives singular
values of the Jacobian. In the unconstrained case, the svs are
pretty awful, and I wouldn't trust the results as a model, though
the minimum is probably OK. The constrained result has a much
larger sum of squares.
2017 Jun 18
2
R_using non linear regression with constraints
I am using nlsLM {minpack.lm} to find the values of parameters a and b of
function myfun which give the best fit for the data set, mydata.
mydata=data.frame(x=c(0,5,9,13,17,20),y = c(0,11,20,29,38,45))
myfun=function(a,b,r,t){
prd=a*b*(1-exp(-b*r*t))
return(prd)}
and using nlsLM
myfit=nlsLM(y~myfun(a,b,r=2,t=x),data=mydata,start=list(a=2000,b=0.05),
lower = c(1000,0),
2017 Jun 18
0
R_using non linear regression with constraints
I've seen a number of problems like this over the years. The fact that the singular values of the Jacobian have
a ration larger than the usual convergence tolerances can mean the codes stop well before the best fit. That is
the "numerical analyst" view. David and Jeff have given geometric and statistical arguments. All views are useful,
but it takes some time to sort them all out and
2017 Jun 18
3
R_using non linear regression with constraints
https://cran.r-project.org/web/views/Optimization.html
(Cran's optimization task view -- as always, you should search before posting)
In general, nonlinear optimization with nonlinear constraints is hard,
and the strategy used here (multiplying by a*b < 1000) may not work --
it introduces a discontinuity into the objective function, so
gradient based methods may in particular be
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'
2017 Jun 18
0
R_using non linear regression with constraints
> On Jun 18, 2017, at 6:24 AM, Manoranjan Muthusamy <ranjanmano167 at gmail.com> wrote:
>
> I am using nlsLM {minpack.lm} to find the values of parameters a and b of
> function myfun which give the best fit for the data set, mydata.
>
> mydata=data.frame(x=c(0,5,9,13,17,20),y = c(0,11,20,29,38,45))
>
> myfun=function(a,b,r,t){
> prd=a*b*(1-exp(-b*r*t))
>
2011 Sep 03
2
problem in applying function in data subset (with a level) - using plyr or other alternative are also welcome
Dear R experts.
I might be missing something obvious. I have been trying to fix this problem
for some weeks. Please help.
#data
ped <- c(rep(1, 4), rep(2, 3), rep(3, 3))
y <- rnorm(10, 8, 2)
# variable set 1
M1a <- sample (c(1, 2,3), 10, replace= T)
M1b <- sample (c(1, 2,3), 10, replace= T)
M1aP1 <- sample (c(1, 2,3), 10, replace= T)
M1bP2 <- sample (c(1, 2,3), 10, replace= T)
2004 Mar 11
1
how to pass extra parameters using call() or similar mechanism ?
I am trying to write a function, which would allow to call various methods
and would pass to them extra arbitrary parameters.
My first attempt was to use call() as illustrated below, but apparently
'...' cannot be used in such context.
How can this be achieved ?
Best regards,
Ryszard
> myfun <- function(method, x, ...) {
+ v <- eval(call(method, x, ...))
+ }
> method =
2020 May 12
0
S3 method dispatch for methods in local environments
Dear Wolfgang,
I think this new behaviour is related to the following R 4.0.0 NEWS item:
> S3 method lookup now by default skips the elements of the search path between the global and base environments.
Your environment "myenv" is attached at position 2 of the search() path
and thus now skipped in S3 method lookup.
I have just noticed that
2005 Feb 01
1
Error in load(dataFile, myEnv)
Dear all,
I just found that some of the packages are not able to load any more,
after I installed R2.0.1 in my Mac, it even affects my old R1.8
installs.
It gives me errors when I load packages that contains "myEnv" settings.
such as: RMySQL, DBI, Rggobi, etc. But others that does not require
"myENV" is all right, like tcltk that only calls the c functions.
The errors
2006 Jun 02
4
function environment
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
how can I automatically access the functions that I loaded into a
separate environment?
> save(A,B,file="myfun.r")
> load("myfun.r",envir=(ENV<-new.env()))
> ls(ENV)
[1] "A" "B"
?"[" turned up that I can access the functions via
> ENV$A
function ()
{
}
> ENV$A()
NULL
Now, how
2010 Oct 20
2
new.env does not recognize parents from subclasses of "environment"
Dear Developers,
A lot has been changed in the R12.0 with respect to behavior of "environment"
subclasses. Many thanks for that.
One small irregularity, though; new.env does not allow the parent to be from S4
subclass.
> setClass("myenv", contains="environment")
[1] "myenv"
> new.env(parent=new("myenv"))
Error in new.env(parent =
2006 Sep 27
1
potential setClass bug (with user-defined environment)
the following returns an error in an 'exists' call on my machine
MyEnv <- new.env()
setClass("Numeric", "numeric", where=MyEnv)
franklin parlamis
> version
_
platform powerpc-apple-darwin8.7.0
arch powerpc
os darwin8.7.0
system powerpc, darwin8.7.0
status beta
major 2
minor 4.0
year
2011 Jul 05
1
Create factor variable by groups
Hi, suppose that I have the following data.frame:
cnae4 cnpj 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 Y
24996 10020470 1 1 2 12 16 21 17 51 43 19 183
24996 10020470 69 91 79 92 91 77 90 96 98 108 891
36145 10020470 0 0 0 0 2 83 112 97 91 144 529
44444 10023333 5 20 60 0 0 0 0 5 20 1000 1110
I would like to create a new variable X that indicates which