similar to: changing default arguments of a function and return the modified function as a result

Displaying 20 results from an estimated 1000 matches similar to: "changing default arguments of a function and return the modified function as a result"

2012 Jan 04
0
[LLVMdev] Volatile Functions
I just ran into an interesting "bug" here. The "bug" itself is not really a bug but a performance issue. The details aren't important but in the course of investigation I came across a general scheduling problem I don't know how to solve. Let's say we have a routine for getting the clock tick of the CPU, called "mysecond." This is a user-written
2005 Sep 06
6
strange behavior of acts_as_taggable
I was testing my models with this new library and I got: >> s.tag "warp" ActiveRecord::StatementInvalid: ERROR: inserción o actualización en la tabla «tags_stories» viola la llave foránea «tags_stories_story_id_fkey» DETAIL: La llave (story_id)=(8) no está presente en la tabla «stories». : INSERT INTO tags_stories ("tag_id", "story_id") VALUES
2002 Jul 02
1
Strange behaviour in plot and points?
Hello R-users I was puzzled by some strange results of an analysis and I found out what is for me a strange behaviour (I won't dare to say a bug) in both plot and points (and I suspect lines and other kind of lower level plots). If you try the following code: > data<-data.frame(dummy1=c(1:10),dummy2=c(1:10)) > plot(data$dummy1,data$dummy3) A plot of the values of dummy1 against
2013 Mar 06
4
Issue when reading a table into R
Hello everyone, I was reading a table into R, and when trying to retrieve it the following message appeared: [ reached getOption("max.print") -- omitted 469376 rows ] Does this mean that R left out 469376 rows? Or R is taking those 469376 rows as well and the limitation is only for printing purposes? Thanks in advance for any help, Best regards, Paul [[alternative HTML version
2010 Sep 03
3
S4 Method Signatures
Hello, If the signature of a method defines which generic it implements then I'm confused about why this minimal example I invented won't work : setGeneric("myFun", function(rs, ...){standardGeneric("myFun")}) setGeneric("myFun", function(cs, ...){standardGeneric("myFun")}) setMethod("myFun", "numeric", function(rs, colour =
2003 Apr 17
4
A function as argument of another function
Dear all, I would like to write a function like: myfun<-function(x,fn) {xx<-exp(x); x*fn(xx)} where fn is a symbolic description of any function with its argument to be specified. Therefore myfun(5,"2+0.3*y^2") should return 5*(2+0.3*exp(5)^2), myfun(5,"log(y)") should return 5*log(exp(5)) and so on. I tried with "expression" and others, but without success.
2011 Sep 26
4
Testing for arguments in a function
I don't understand how this function can subset by i when i is missing.... ## My function: myfun = function(vec, i){ ret = vec[i] ret } ## My data: i = 10 vec = 1:100 ## Expected input and behavior: myfun(vec, i) ## Missing an argument, but error is not caught! ## How is subsetting even possible here??? myfun(vec) Is there a way to check for missing function arguments, *and*
2006 Feb 02
2
How to get the namespace of a function?
I declared the environment of the function myfun to be NULL as follows: environment(myfun) <- NULL Later on I called that myfun and got an error message because the function index() in the zoo package was called inside myfun and was not visible: Error in myfun(args) : couldn't find function "index" I tried to use zoo::index() instead of index(), but that did not work. In fact,
2013 Jun 07
1
It seams that fast99 function (sensitivity package) does not work out for norm distribution.
Dear all mailing listers, Does Anyone have the same problem as mine when using the fast99 (extended-FAST method) to perform SA of model with norm distribution inputs? See the simple example given following. Any suggestion will be greatly appreciated. Thank you! Marino # Simple example # 1. uniform version (It works well) library(sensitivity) Myfun<-function(x){return(rowSums(x))} SA1
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 =
2015 Oct 22
2
Changed behaviour when passing a function?
Of course (and unsurprisingly) Duncan is correct. I see that behavior in R 3.1.0, as well as the modern ones Duncan mentioned. What I said is true, as far as it goes, but the symbol being resolved is FUN, so when looking for a function it doesn't find the function version of round. Did you perhaps have a function named FUN in your global environment? If so you are being bitten by what I
2011 Feb 02
1
pass nrow(x) to dots in function(x){plot(x,...)}
Dear Rers, I have a function to barplot() a matrix, eg myfun <- function(x, ...) { barplot(x , ... )} (The real function is more complicated, it does things to the matrix first.) So I can do: m1 <- matrix(1:20,4) myfun(m1) myfun(m1, main="My title") I'd like to be able to add the number of rows of the matrix passed to the function to the "..." argument, eg
2006 Sep 27
2
How to pass expression as an argument
Hi, I am writing a function and need to pass a function expression as an argument, for instance, myfun <- function( express) { x<- c(1,2,3) y<-express } if I call the above function by myfun( x*2 ), I get 2 as the result, instead of 2,4,6 , could someone help me to fix this problem ? Furthermore, is that
2015 Oct 22
3
Changed behaviour when passing a function?
Hi all, When teaching this year's class, I was quite amazed that one of my examples didn't work any longer. I wanted to illustrate the importance of match.fun() with following code: myfun <- function(x, FUN, ...){ FUN(x, ...) } round <- 2 myfun(0.85, FUN = round, digits=1) I expected to see an error, but this code doesn't generate one. It seems as if in the current R
2002 Jan 07
1
Mishandling missing "..." (PR#1247)
R> myfun <- function(x, ...) {x[...] <- 0; x} R> myfun(3) Error in myfun(3) : SubAssignArgs: invalid number of arguments It fails because no ... was passed. The workaround (and desired behavior) is: R> myfun <- function(x, ...) {if (missing(...)) x[] <- 0 else x[...] <- 0; x} R> myfun(3) [1] 0 Deja vu? This is the one piece of my PR#1110 (Oct 3, 2001) that I
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.
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'
2011 Oct 11
2
stop()
Suppose I have a function, such as the toy example below: myFun <- function(x, max.iter = 5) { for(i in 1:10){ result <- x + i iter <- i if(iter == max.iter) stop('Max reached') } result } I can of course do this: myFun(10, max.iter = 11) However, if I reach the maximum
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]
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