Re: [Rd] S4 method defined but not used
Dear Martin, thanks for giving it a try. I forgot to mention I had removed the .RData, and started R without using the .Rprofile. R --vanilla did not help. However, I made another try on another computer with the same packages, R version, and OS, and I fail to reproduce this error. Best regards Thibaut > Hi Thibaut -- > > For what it's worth, I can't reproduce this problem, and in a new R > session after library(adegenet) I have > >> sessionInfo() > R version 2.11.0 Patched (2010-05-01 r51886) > x86_64-unknown-linux-gnu > > locale: > [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C > [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 > [5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8 > [7] LC_PAPER=en_US.UTF-8 LC_NAME=C > [9] LC_ADDRESS=C LC_TELEPHONE=C > [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C > > attached base packages: > [1] stats graphics grDevices datasets utils methods base > > other attached packages: > [1] adegenet_1.2-4 MASS_7.3-5 > > which has a different set of attached / loaded packages -- maybe you are > picking up something from .RData or .Rprofile, and you need to start R > with --vanilla? > > Martin __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] possible bug in formals
Dear Brian and Uwe, Thanks a lot for the clarification. I made the naive assumption that numeric constants in R are similar to those in C. Two questions still remain: (1) when I have a function f<- function(a=1,b=-1) { a+b } is it safe to use val <- as.character(deparse(formals(f)$b)) to obtain a string that contains the default value for argument "b". (Does is also work for other arguments with some default of arbitrary class?) (2) I have seen that packages like gWidget (in function ggenericwidget) use a statement like switch(class(formals(f)$b), numeric = { }, character = { }, class = { }, for automatically processing function arguments. in the case of "b=-1" this procedure obviously fails. (I found this behavior of 'formals' while playing around with packages "gWidgets" and "fgui" from CRAN). Is there a safe workaround for this problem? That is, is there a safe function that returns class "numeric" for an exresion like "-1" or "-Inf"? Josef On Sun, May 23, 2010 at 03:52:00PM +0100, Prof Brian Ripley wrote: > Documented too: from ?NumericConstants > > Note that a leading plus or minus is not regarded by the parser as > part of a numeric constant but as a unary operator applied to the > constant. > > > > On Sun, 23 May 2010, Uwe Ligges wrote: > > > > > > > On 23.05.2010 16:14, Josef Leydold wrote: > >> Hi, > >> > >> I am a little bit surprised by the following output of > >> 'formals'. Is this the intended behavior? > >> > >>> f<- function(a=1,b=-1) { a+b } > >>> class(formals(f)$a) > >> [1] "numeric" > >>> class(formals(f)$b) > >> [1] "call" > >> > >> > >> Josef > >> > >> > > > > > > Yes, the arguments have not yet been evaluated, hence -1 is still a > > language > > object. > > > > Try to write > > f<- function(a= +1, b= -1) { a+b } > > and you will find that this is a fascinating feature. > > > > Uwe Ligges > > > > __ > > R-devel@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-devel > > > > -- > Brian D. Ripley, rip...@stats.ox.ac.uk > 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 > -- - Josef Leydold | WU (Vienna University of Economics and Business) | Institute for Statistics and Mathematics - Augasse 2-6 | Tel. +43 1 31336 4695 A-1090 Vienna | FAX+43 1 31336 774 European Union | email josef.leyd...@wu.ac.at - Alles Unglueck kam daher, dass die Denkenden nicht mehr handeln konnten, und die Handelnden keine Zeit mehr fanden zu denken. (Marlen Haushofer) __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] possible bug in formals
On Mon, 24 May 2010, Josef Leydold wrote: Dear Brian and Uwe, Thanks a lot for the clarification. I made the naive assumption that numeric constants in R are similar to those in C. Two questions still remain: (1) when I have a function f<- function(a=1,b=-1) { a+b } is it safe to use val <- as.character(deparse(formals(f)$b)) to obtain a string that contains the default value for argument "b". (Does is also work for other arguments with some default of arbitrary class?) But the defualt value is not character, so this cannot in general be done. (2) I have seen that packages like gWidget (in function ggenericwidget) use a statement like switch(class(formals(f)$b), numeric = { }, character = { }, class = { }, for automatically processing function arguments. in the case of "b=-1" this procedure obviously fails. (I found this behavior of 'formals' while playing around with packages "gWidgets" and "fgui" from CRAN). Is there a safe workaround for this problem? That is, is there a safe function that returns class "numeric" for an exresion like "-1" or "-Inf"? Why are you using class() when you seem to mean typeof()? But the short answer is you appear to be trying to circumvent the language, and who really cares what the default is? If it is used, it is evaluated, and then you can simply do typeof(b). And if it is not used, who cares what it is? Josef On Sun, May 23, 2010 at 03:52:00PM +0100, Prof Brian Ripley wrote: Documented too: from ?NumericConstants Note that a leading plus or minus is not regarded by the parser as part of a numeric constant but as a unary operator applied to the constant. On Sun, 23 May 2010, Uwe Ligges wrote: On 23.05.2010 16:14, Josef Leydold wrote: Hi, I am a little bit surprised by the following output of 'formals'. Is this the intended behavior? f<- function(a=1,b=-1) { a+b } class(formals(f)$a) [1] "numeric" class(formals(f)$b) [1] "call" Josef Yes, the arguments have not yet been evaluated, hence -1 is still a language object. Try to write f<- function(a= +1, b= -1) { a+b } and you will find that this is a fascinating feature. Uwe Ligges __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Brian D. Ripley, rip...@stats.ox.ac.uk 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 -- - Josef Leydold | WU (Vienna University of Economics and Business) | Institute for Statistics and Mathematics - Augasse 2-6 | Tel. +43 1 31336 4695 A-1090 Vienna | FAX+43 1 31336 774 European Union | email josef.leyd...@wu.ac.at - Alles Unglueck kam daher, dass die Denkenden nicht mehr handeln konnten, und die Handelnden keine Zeit mehr fanden zu denken. (Marlen Haushofer) -- Brian D. Ripley, rip...@stats.ox.ac.uk 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
[Rd] Accessing functions from a package
Hi All, I created a .R file with source code that accesses functions from a R package (example, fTrading). I then run the created application in two different configurations: 1. I started a R session, and then ran the application using the source ("my_application.R") command, and I measured the time the application ran. 2. I started 2 R sessions in the same processor, and executed the same source ("my_application.R") command, and measured the times the application ran. The times I measured for each applications in #2 was slower than the times I measured for the application in #1. The application was run in a 4-core machine running Linux. When the application ran, i used "mpstat" to look at the CPU usage. For #1, the CPU usage was 25%, and for #2, the CPU usage was 50%. No other process was running in the machine. My question is, why would #2 be slower than #1? Thanks, Peter [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel