similar to: OOP and passing by value

Displaying 20 results from an estimated 2000 matches similar to: "OOP and passing by value"

2018 Jul 27
3
SHELL() function Asterisk 13 - can only accept one paramter in string?
Hi all This is a followup on my post "Asterisk 13 - system() dialplan app cannot call bash scripts" from yesterday I've given up trying to use system() to call BASH scripts with parameters from Asterisk 13. Turned out under Asterisk 13.22.0 System() DOES work, but only if you do NOT attempt to pass any parameters to the called script. This works, and reliably calls the script:
2006 Apr 04
2
Return function from function with minimal environment
Hi, this relates to the question "How to set a former environment?" asked yesterday. What is the best way to to return a function with a minimal environment from a function? Here is a dummy example: foo <- function(huge) { scale <- mean(huge) function(x) { scale * x } } fcn <- foo(1:10e5) The problem with this approach is that the environment of 'fcn' does not
2007 Aug 22
3
integrate
Hi, I am trying to integrate a function which is approximately constant over the range of the integration. The function is as follows: > my.fcn = function(mu){ + m = 1000 + z = 0 + z.mse = 0 + for(i in 1:m){ + z[i] = rnorm(1, mu, 1) + z.mse = z.mse + (z[i] - mu)^2 + } + return(z.mse/m) + } > my.fcn(-10) [1] 1.021711 > my.fcn(10) [1] 0.9995235 > my.fcn(-5) [1] 1.012727 > my.fcn(5)
2010 Mar 24
1
with data in the form of an R data objecte: Monte Carlo simulation in R
Hi, please use the following the matrix z as the example: x<-c(2,4,5,7,6,9,8,2,0) y<-matrix(x,3,3) z<-apply(y,2,function(x)x/sum(x)) z On Tue, Mar 23, 2010 at 6:59 PM, David Winsemius <dwinsemius@comcast.net>wrote: > > On Mar 23, 2010, at 9:05 PM, Hongwei Dong wrote: > > Hi, R-helpers, >> >> I'm trying to use R to do a Monte Carlo simulation and
2016 Mar 13
1
formals(x)<- drops attributes including class
Just checking in to see whether it is intended or not that assigning new formals to a function/closure causes any attributes to be dropped: EXAMPLE: > fcn <- structure(function() {}, foo="foo", class=c("foo")) > str(fcn) function () - attr(*, "srcref")=Class 'srcref' atomic [1:8] 1 18 1 30 18 30 1 1 .. ..- attr(*, "srcfile")=Classes
2011 Mar 15
1
Problem with nls.lm function of minpack.lm package.
Dear R useRs, I have a problem with nls.lm function of minpackl.lm package. I need to fit the Van Genuchten Model to a set of data of Theta and hydraulic conductivity with nls.lm function of minpack.lm package. For the first fit, the parameter estimates keep changing even after 1000 iterations (Th) and I have a following error message for fit of hydraulic conductivity (k); Reason for
2003 Oct 30
2
'nls' and its arguments
Dear R experts! I'd to fit data by 'nls' with me-supplied function 'fcn'. 1) I'd like 'fcn' to accept arbitrary arguments, i.e. I defined it as f(...) {<body>}. (Ok, that's not actually impotant). 2) Second, I would NOT like to supply every parameter in the formula. To illustrate this, let's look at the last example of 'nls' help
2010 May 14
1
debugging substitute function in R 2.11
Dear list, A while ago I found in the web a function (sadly I can't credit the author as I don't remember where I picked it up from) whose output is a dataframe that lists for every object in the global environment its class, mode, dim & length (where applicable). It is meant to be an upgrade to the ls () function with a far more informative and detailed output and it quickly became
2024 Feb 06
1
[EXTERNAL] Re: NOTE: multiple local function definitions for ?fun? with different formal arguments
Here's a dummy example that I think illustrates the problem: toto <- function() { if (runif(1) < 0.5) function(a) a else function(a,b) a+b } > fcn <- toto() > fcn(1,2) [1] 3 > fcn <- toto() > fcn(1,2) [1] 3 > fcn <- toto() > fcn(1,2) Error in fcn(1, 2) : unused argument (2) How can you use the returned function, if you get different arguments?
2013 Feb 05
1
integrate: Don't do this?
When I run the following function HQ2 <- function(n) { nv <- 6 * sqrt(n) fcn <- function(z) { pchisq(z^2 / 36, n - 1) * dnorm(nv - z) } ## I want the integral from 0 to infinity: f.Inf <- integrate(fcn, 0, Inf) ## Doc: "Don't do this": f.100 <- integrate(fcn, 0, 100) cbind(f.Inf, f.100) } I get, for n = 9 and
2008 Apr 22
4
how to convert non numeric data into numeric?
I am having the following error in my function function(theta,reqdIRR) { theta1<-theta[1] theta2<-theta[2] n<-length(reqdIRR) constant<- n*(theta1+theta2) sum1<-lapply(reqdIRR*exp(theta1),FUN = sum) sum2<-lapply(exp(theta2 - reqdIRR*exp(theta1)),FUN = sum) sum = sum1 + sum2 log.fcn = constant - as.numeric(sum) result = - log.fcn return(result) } *error :
2007 Sep 29
2
Help with functions (iterations)
Hello: I am a bit confused by this problem. Can anyone give me some advice on this I would greatly appreciate it. Thank you for all your help. Need to create a for loop that saves the estimate of pi from each 0f 100 separate iterations and store it in a numeric vector (of length 100). The for loop should be placed in a function that allows the user to vary the sample size, the simulation size,
2002 Jan 23
1
Question about substitute (and eval, parse and deparse)
I would like to define a function at run-time, but I just can't make it work (please don't question why I want to do this, because that would be too much to explain). For example, I want to define the the following function foo <- function(x) { cat("Function", "foo", "was called with argument", x, ".\n") } However, I would like to
2006 Apr 05
1
predict.smooth.spline.fit and Recall() (Was: Re: Return function from function and Recall())
Hi, forget about the below details. It is not related to the fact that the function is returned from a function. Sorry about that. I've been troubleshooting soo much I've been shoting over the target. Here is a much smaller reproducible example: x <- 1:10 y <- 1:10 + rnorm(length(x)) sp <- smooth.spline(x=x, y=y) ypred <- predict(sp$fit, x) # [1] 2.325181 2.756166 ...
2011 Dec 14
1
uniroot function question
I have one equation, two unknowns, so I am trying to build the solution set by running through possible values for one unknown, and then using uniroot to solve for the accompanying second solution, then graphing the two vectors. p0 = .36 f = function(x) 0.29 * exp(5.66*(x - p0)) f.integral = integrate(f, p0, 1) p1 = p0 + .01 i = 1 n = (1 - p0)/.01 p1.vector = rep(0,n) p2.vector = rep(0,n) for (i
2008 Jan 08
1
use "save.image" inside a function?
Hi, All I'm trying to save the workspace as a Check Point for possible future come back. The "save.image" function works if the whole coding is in a main function: rm(list=ls()) t = 1 t = t+1 print(paste("before",t)) # [1] "before 2" save.image("tt.RData") t = t+1 print(paste("after",t)) # [1] "after 3"
2006 Sep 24
4
SWIG exceptions
I was trying to fix the problem with wxImage and the char */unsigned char * thing today and I was going to hand-write the functions to translate between the two. While doing so I decided I''d clean up the SWIG error message to make it more clear. Here''s an example SWIG-generated argument error: in method SetData'', argument 2 of type ''wxImage *''
2013 Sep 30
1
how to interpose my own "[" function?
I want to create my own "[" function (for use on vectors, matrices, arrays, etc.), which calls the stock R "[", does some additional work, and then finally returns the modified result. But, how do I properly call the stock R "[" function? It takes a varying number of positional arguments, and its R-level closure is just: .Primitive("[") It's
2005 Jun 10
1
Exiting R and package detachment?
Hi, is there away to assure that a package is detached when R quits? I know about .Last(), but that requires the user to setup that function. What I am looking for is a way for the package to do this itself, without asking the user to edit "their" .Last(). From ?setHook I know that: "...when an R is finished, packages are not detached and namespaces are not unloaded, so
2014 Dec 08
2
[LLVMdev] Virtual register problem in X86 backend
Hi, I'm having trouble using virtual register in the X86 backend. I implemented a new intrinsic and I use a custom inserter. The goal of the intrinsic is to set the content of the stack to zero at the end of each function. Here is my code: MachineBasicBlock * X86TargetLowering::EmitBURNSTACKWithCustomInserter( MachineInstr *MI, MachineBasicBlock