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 version match.fun() is added automatically. I've scrolled through the complete R News section specifying all the changes and bug fixes, starting from 3.0.0. I couldn't find anything on that change in behaviour though. Where can I find more information on what changed exactly? Thanks Cheers Joris -- Joris Meys Statistical consultant Ghent University Faculty of Bioscience Engineering Department of Mathematical Modelling, Statistics and Bio-Informatics tel : +32 (0)9 264 61 79 Joris.Meys at Ugent.be ------------------------------- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php [[alternative HTML version deleted]]
Joris, When a function call (detected via the parenthesis) R does the equivalent of get(..., mode="function") to resolve the symbol.> round = 2 > round(5.3)[1] 5> get("round")[1] 2> get("round", mode = "function")function (x, digits = 0) .Primitive("round") It's done this for a while, but didn't always do it, I think. I don't know when the change happened. Best, ~G On Thu, Oct 22, 2015 at 10:59 AM, Joris Meys <jorismeys at gmail.com> wrote:> 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 version match.fun() is added automatically. > > I've scrolled through the complete R News section specifying all the > changes and bug fixes, starting from 3.0.0. I couldn't find anything on > that change in behaviour though. Where can I find more information on what > changed exactly? > > Thanks > Cheers > Joris > > -- > Joris Meys > Statistical consultant > > Ghent University > Faculty of Bioscience Engineering > Department of Mathematical Modelling, Statistics and Bio-Informatics > > tel : +32 (0)9 264 61 79 > Joris.Meys at Ugent.be > ------------------------------- > Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Gabriel Becker, PhD Associate Scientist (Bioinformatics) Genentech Research [[alternative HTML version deleted]]
On 22/10/2015 1:59 PM, Joris Meys wrote:> 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 version match.fun() is added automatically. > > I've scrolled through the complete R News section specifying all the > changes and bug fixes, starting from 3.0.0. I couldn't find anything on > that change in behaviour though. Where can I find more information on what > changed exactly? >When you say "current R version", what do you mean? I see an error: > myfun <- function(x, FUN, ...){ + FUN(x, ...) + } > round <- 2 > myfun(0.85, FUN = round, digits=1) Error in myfun(0.85, FUN = round, digits = 1) (from #2) : could not find function "FUN" I see this in 3.2.2, R-patched and R-devel. Duncan Murdoch
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 mentioned before.> FUN = function(...) 1 > myfun <- function(x, FUN, ...){+ FUN(x, ...) + }> round <- 2 > myfun(0.85, FUN = round, digits=1)[1] 1 ~G On Thu, Oct 22, 2015 at 2:25 PM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:> On 22/10/2015 1:59 PM, Joris Meys wrote: > >> 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 version match.fun() is added automatically. >> >> I've scrolled through the complete R News section specifying all the >> changes and bug fixes, starting from 3.0.0. I couldn't find anything on >> that change in behaviour though. Where can I find more information on what >> changed exactly? >> >> > When you say "current R version", what do you mean? I see an error: > > > myfun <- function(x, FUN, ...){ > + FUN(x, ...) > + } > > round <- 2 > > myfun(0.85, FUN = round, digits=1) > Error in myfun(0.85, FUN = round, digits = 1) (from #2) : > could not find function "FUN" > > I see this in 3.2.2, R-patched and R-devel. > > Duncan Murdoch > > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Gabriel Becker, PhD Associate Scientist (Bioinformatics) Genentech Research [[alternative HTML version deleted]]