Re: [Rd] Getting param names of primitives
Thanks! Worked like a charm. Regards, M. Manese On 7/11/07, Prof Brian Ripley [EMAIL PROTECTED] wrote: formals(args(log)) $x $base exp(1) gives what formals(log) used to. On Wed, 11 Jul 2007, miguel manese wrote: Hi, In the latest R this does not work anymore args - formals(log) because log is primitive. Is there any other way to get the argument list? I just need the name of the parameter to display some error message about it. I have looked at args() but I can't find anything to extract the argument names from it. Thanks, M. Manese -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Getting param names of primitives
BDR == Prof Brian Ripley [EMAIL PROTECTED] on Wed, 11 Jul 2007 05:48:56 +0100 (BST) writes: formals(args(log)) BDR $x BDR $base BDR exp(1) BDR gives what formals(log) used to. (I knew). I've been asking myself several times now, if we should not make formals() do this automatically. I know that the change might break some code which has used things like if(is.null(formals(fun))) { ## treat fun as a primitive function } but I think R has provided is.primitive(.) long enough now so that we could consider the change. Martin BDR On Wed, 11 Jul 2007, miguel manese wrote: Hi, In the latest R this does not work anymore args - formals(log) because log is primitive. Is there any other way to get the argument list? I just need the name of the parameter to display some error message about it. I have looked at args() but I can't find anything to extract the argument names from it. Thanks, M. Manese BDR -- BDR Brian D. Ripley, [EMAIL PROTECTED] BDR Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ BDR University of Oxford, Tel: +44 1865 272861 (self) BDR 1 South Parks Road, +44 1865 272866 (PA) BDR Oxford OX1 3TG, UKFax: +44 1865 272595 BDR __ BDR R-devel@r-project.org mailing list BDR https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Getting param names of primitives
My problem is that if we make formals() work on primitives, people will expect formals(log) - value to work, and it cannot. On Wed, 11 Jul 2007, Martin Maechler wrote: BDR == Prof Brian Ripley [EMAIL PROTECTED] on Wed, 11 Jul 2007 05:48:56 +0100 (BST) writes: formals(args(log)) BDR $x BDR $base BDR exp(1) BDR gives what formals(log) used to. (I knew). I've been asking myself several times now, if we should not make formals() do this automatically. I know that the change might break some code which has used things like if(is.null(formals(fun))) { ## treat fun as a primitive function } but I think R has provided is.primitive(.) long enough now so that we could consider the change. Martin BDR On Wed, 11 Jul 2007, miguel manese wrote: Hi, In the latest R this does not work anymore args - formals(log) because log is primitive. Is there any other way to get the argument list? I just need the name of the parameter to display some error message about it. I have looked at args() but I can't find anything to extract the argument names from it. Thanks, M. Manese BDR -- BDR Brian D. Ripley, [EMAIL PROTECTED] BDR Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ BDR University of Oxford, Tel: +44 1865 272861 (self) BDR 1 South Parks Road, +44 1865 272866 (PA) BDR Oxford OX1 3TG, UKFax: +44 1865 272595 BDR __ BDR R-devel@r-project.org mailing list BDR https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Getting param names of primitives
Prof Brian Ripley [EMAIL PROTECTED] writes: My problem is that if we make formals() work on primitives, people will expect formals(log) - value to work, and it cannot. But it could give an informative error message. Asking for formals() seems to make sense so making it work seems like a good idea. I'll agree that it working might encourage someone to try formals-(), but the fact that it cannot do anything but error seems like a strange reason not to make formals() work. + seth -- Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center http://bioconductor.org __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Getting param names of primitives
Even that does not appear to work everywhere. Either of these returns NULL: formals(args({)) formals(args(match.fun({))) R.version.string # XP [1] R version 2.5.1 (2007-06-27) On 7/11/07, Prof Brian Ripley [EMAIL PROTECTED] wrote: formals(args(log)) $x $base exp(1) gives what formals(log) used to. On Wed, 11 Jul 2007, miguel manese wrote: Hi, In the latest R this does not work anymore args - formals(log) because log is primitive. Is there any other way to get the argument list? I just need the name of the parameter to display some error message about it. I have looked at args() but I can't find anything to extract the argument names from it. Thanks, M. Manese -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Getting param names of primitives
On 7/11/2007 9:40 AM, Seth Falcon wrote: Prof Brian Ripley [EMAIL PROTECTED] writes: My problem is that if we make formals() work on primitives, people will expect formals(log) - value to work, and it cannot. But it could give an informative error message. Asking for formals() seems to make sense so making it work seems like a good idea. I'll agree that it working might encourage someone to try formals-(), but the fact that it cannot do anything but error seems like a strange reason not to make formals() work. But primitives don't have formals, and that's why you can't set them. Having formals(primitive) work just makes it harder to talk about the language. Closures have formals, primitives don't. Both have args. If you want to work with the args of a function, use the args. Duncan Murdoch __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Getting param names of primitives
On Wed, 11 Jul 2007, Duncan Murdoch wrote: On 7/11/2007 9:40 AM, Seth Falcon wrote: Prof Brian Ripley [EMAIL PROTECTED] writes: My problem is that if we make formals() work on primitives, people will expect formals(log) - value to work, and it cannot. But it could give an informative error message. Asking for formals() seems to make sense so making it work seems like a good idea. I'll agree that it working might encourage someone to try formals-(), but the fact that it cannot do anything but error seems like a strange reason not to make formals() work. But primitives don't have formals, and that's why you can't set them. Having formals(primitive) work just makes it harder to talk about the language. Closures have formals, primitives don't. Both have args. If you want to work with the args of a function, use the args. I agree: I was going to reply to Seth that the main reason was that 'formals() ought to refer to formals which primitives lack'. And note too that args(primitive) does not work for all primitives, as some are really part of the language (e.g. for(), return()). Exactly which are is perhaps debatable, and the person who implemented the mechanism got to decide. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Getting param names of primitives
These don't work either: args(match.fun({)) args({) On 7/11/07, Prof Brian Ripley [EMAIL PROTECTED] wrote: On Wed, 11 Jul 2007, Duncan Murdoch wrote: On 7/11/2007 9:40 AM, Seth Falcon wrote: Prof Brian Ripley [EMAIL PROTECTED] writes: My problem is that if we make formals() work on primitives, people will expect formals(log) - value to work, and it cannot. But it could give an informative error message. Asking for formals() seems to make sense so making it work seems like a good idea. I'll agree that it working might encourage someone to try formals-(), but the fact that it cannot do anything but error seems like a strange reason not to make formals() work. But primitives don't have formals, and that's why you can't set them. Having formals(primitive) work just makes it harder to talk about the language. Closures have formals, primitives don't. Both have args. If you want to work with the args of a function, use the args. I agree: I was going to reply to Seth that the main reason was that 'formals() ought to refer to formals which primitives lack'. And note too that args(primitive) does not work for all primitives, as some are really part of the language (e.g. for(), return()). Exactly which are is perhaps debatable, and the person who implemented the mechanism got to decide. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Getting param names of primitives
Hi, In the latest R this does not work anymore args - formals(log) because log is primitive. Is there any other way to get the argument list? I just need the name of the parameter to display some error message about it. I have looked at args() but I can't find anything to extract the argument names from it. Thanks, M. Manese __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Getting param names of primitives
formals(args(log)) $x $base exp(1) gives what formals(log) used to. On Wed, 11 Jul 2007, miguel manese wrote: Hi, In the latest R this does not work anymore args - formals(log) because log is primitive. Is there any other way to get the argument list? I just need the name of the parameter to display some error message about it. I have looked at args() but I can't find anything to extract the argument names from it. Thanks, M. Manese -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel