Re: [Rd] Strange behavior of assign in a S4 method.
Where did you get the idea that 'x' comes from the parent frame? There is no guarantee of this, and you are relying on/stumbling over implementation details here. (An extra call is inserted by setMethod() to handle the matching up of argumnets, but that is something which may change, and has changed in the history of the 'methods' package.) Note that 'x' might be an expression, even foo2(3, y=5). You need to check it is a symbol. It would seem to me to be much better to use a replacement function here (via setReplaceMethod in S4 land) and let the parser do most of the basic checking. Incidentally, at least in modern English, an assignation is (Collins English Dictionary) a secret or forbidden arrangement to meet and it seems rather that you _are_ trying to do something 'secret or forbidden'. (I suspect you mean 'assignment'.) On Mon, 15 Mar 2010, Christophe Genolini wrote: Hi the list, I define a method that want to change an object without assignation (foo(x) and not x-foo(x)) using deparse and assign. But when the argument of the method does not match *exactly* with the definition of the generic function, assign does not work... Anything wrong? Christophe #-- Does not work --# setGeneric(foo1,function(x,...){standardGeneric(foo1)}) setMethod(f=foo1,signature=numeric,definition= function(x,y=1,...){ nameX-deparse(substitute(x)) x - x^2 assign(nameX,x,envir=parent.frame()) } ) e - 3 foo1(e,y=5) cat(e) #-- Does work --# setGeneric(foo2,function(x,...){standardGeneric(foo2)}) setMethod(f=foo2,signature=numeric,definition= function(x,...){ nameX-deparse(substitute(x)) x - x^2 assign(nameX,x,envir=parent.frame()) } ) e - 3 foo2(e,y=5) cat(e) __ 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 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] 2.11.0 timing (was translation for R-2.11)
The enquiry below reminds me that we really ought to be setting a schedule for 2.11.0. With Easter now likely to be during the pre-2.11.0 period, we may have (other)availability issues. I've updated the translation templates this morning, so the advice to Detlef was it was OK provided he worked on those versions. But if anyone is planning extensive changes before 2.11.0 we ought to warn translators. Brian -- 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 -- Forwarded message -- Date: Tue, 16 Mar 2010 09:06:32 From: Detlef Steuer detlef.ste...@hsu-hamburg.de To: Prof Brian Ripley rip...@stats.ox.ac.uk Subject: translation for R-2.11 Brian, would now be a good time to go over the translations? Most probably I won't have to much time in the first half of April, so I want to work with enough distance to any deadline. Best regards Detlef __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Strange behavior of assign in a S4 method.
Dear Wolfgang, Thanks for the showMethod and the link. Perhaps juggling with the 'n' argument of 'parent.frame' could help in hacking something together that 'works' I just change the argument list of foo2 to perfectly match with the definition. but as far as I can see what you want to is an abuse of R's pass by value / functional language semantics. Yes I kown. When I learnt object programming, one of the basic was that some methods was design to change internals value of the fields. It is what I try to do here. For example, try these and check whether this results in what you intended: foo2(3) foo2(e+2) sapply(1:5, foo2) ls() This will not apply, because I my case, the function foo2 is avalable only for object of class FooClass and the only possible use will be : toto - new(FooClass) foo2(toto) Best wishes Christophe Best wishes Wolfgang Christophe Genolini scripsit 15/03/10 11:33: Hi the list, I define a method that want to change an object without assignation (foo(x) and not x-foo(x)) using deparse and assign. But when the argument of the method does not match *exactly* with the definition of the generic function, assign does not work... Anything wrong? Christophe #-- Does not work --# setGeneric(foo1,function(x,...){standardGeneric(foo1)}) setMethod(f=foo1,signature=numeric,definition= function(x,y=1,...){ nameX-deparse(substitute(x)) x - x^2 assign(nameX,x,envir=parent.frame()) } ) e - 3 foo1(e,y=5) cat(e) #-- Does work --# setGeneric(foo2,function(x,...){standardGeneric(foo2)}) setMethod(f=foo2,signature=numeric,definition= function(x,...){ nameX-deparse(substitute(x)) x - x^2 assign(nameX,x,envir=parent.frame()) } ) e - 3 foo2(e,y=5) cat(e) __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Wolfgang Huber EMBL http://www.embl.de/research/units/genome_biology/huber/contact __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] mean(trim=, c(NA,...), na.rm=FALSE) does not return NA
Both of the following should return NA, but do not in R version 2.11.0 Under development (unstable) (2010-03-07 r51225) on 32-bit Windows: mean(c(1,10,100,NA), trim=.1) Error in sort.int(x, partial = unique(c(lo, hi))) : index 4 outside bounds mean(c(1,10,100,NA), trim=.26) [1] 55 With na.rm=TRUE they give the correct results. (mean() would be so much simpler if we didn't have to worry about the seldom-used trim= argument.) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Problems compiling a simple source package on MacOS X
Hello. I wrote a package (that contains C source) that I've been compiling and running on both Linux and Windows for about a year. However, that same source package fails to compile on MacOS (10.4.11, PowerPC G4, Xcode installed, gcc version 4.0.1, make version 3.80, ld version cctools-590.23.2.obj~17). There is nothing platform-specific in the code-- just numerical functions that I wrote in C so they would run faster. It's been a while since I hacked Macs... perhaps there is some preliminary step I'm overlooking that's so obvious to Mac R developers that nobody even bothers to mention it? I would greatly appreciate any suggestions on where I should look in order to troubleshoot this problem. Thank you kindly. PS: I get the following message when trying to compile either via R CMD INSTALL or via the Packages Data menu within the R console: * installing to library '/Users/barshop_lab/Library/R/2.10/library' * installing *source* package 'Survomatic' ... ** libs ** arch - i386 gcc -arch i386 -std=gnu99 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/i386 -I/usr/local/include-fPIC -g -O2 -c haz.c -o haz.o gcc -arch i386 -std=gnu99 -dynamiclib -Wl,-headerpad_max_install_names -mmacosx-version-min=10.4 -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -o Survomatic.so haz.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation ld: /Library/Frameworks/R.framework/../R.framework/R load command 17 unknown cmd field /usr/bin/libtool: internal link edit command failed make: *** [Survomatic.so] Error 1 ERROR: compilation failed for package 'Survomatic' * removing '/Users/barshop_lab/Library/R/2.10/library/Survomatic' * restoring previous '/Users/barshop_lab/Library/R/2.10/library/Survomatic' __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Problems compiling a simple source package on MacOS X
Alex, On Mar 16, 2010, at 14:19 , Alex Bokov wrote: Hello. I wrote a package (that contains C source) that I've been compiling and running on both Linux and Windows for about a year. However, that same source package fails to compile on MacOS (10.4.11, PowerPC G4, Xcode installed, gcc version 4.0.1, make version 3.80, ld version cctools-590.23.2.obj~17). There is nothing platform-specific in the code-- just numerical functions that I wrote in C so they would run faster. It's been a while since I hacked Macs... perhaps there is some preliminary step I'm overlooking that's so obvious to Mac R developers that nobody even bothers to mention it? I would greatly appreciate any suggestions on where I should look in order to troubleshoot this problem. You don't have the necessary tools -- your compiler+linker is too ancient (so is your OS, but that's another story). Please install Xcode 2.4 or higher -- see R for Mac FAQ and/or visit http://R.research.att.com/tools/ In addition, please consider looking at R-SIG-Mac where Mac-related discussion takes place and this has been discussed before (stuffing the error in google gives exactly the relevant hit on the list...) Cheers, Simon Thank you kindly. PS: I get the following message when trying to compile either via R CMD INSTALL or via the Packages Data menu within the R console: * installing to library '/Users/barshop_lab/Library/R/2.10/library' * installing *source* package 'Survomatic' ... ** libs ** arch - i386 gcc -arch i386 -std=gnu99 -I/Library/Frameworks/R.framework/ Resources/include -I/Library/Frameworks/R.framework/Resources/ include/i386 -I/usr/local/include-fPIC -g -O2 -c haz.c -o haz.o gcc -arch i386 -std=gnu99 -dynamiclib -Wl,- headerpad_max_install_names -mmacosx-version-min=10.4 -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/ local/lib -o Survomatic.so haz.o -F/Library/Frameworks/ R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation ld: /Library/Frameworks/R.framework/../R.framework/R load command 17 unknown cmd field /usr/bin/libtool: internal link edit command failed make: *** [Survomatic.so] Error 1 ERROR: compilation failed for package 'Survomatic' * removing '/Users/barshop_lab/Library/R/2.10/library/Survomatic' * restoring previous '/Users/barshop_lab/Library/R/2.10/library/ Survomatic' __ 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] Problem with S3 to S4 transition
Hello to everybody I am developing a package using R and have the following problem: I used to work in a mixture of S3 and S4 mechanism environment: as a matter of fact, I used to define my classes (say DB for illustration) using the setClass function (with representation field), and I was using the S3 implicit mechanism writing the functions: print.DB and plot.DB. Recently, I read some interesting papers on the use of S4 mechanism and was convinced that I would have some benefit in turning everything on S4 formalism. This is the reason why I simply renamed my previous functions into DB.print and DB.plot (by analogy with other functions where the Class name is the leading part of the name). My idea was to use the setMethod principle to set the DB.print function as the function for the print method on the DB class. Therefore, in the .First.Lib file of my package, I introduced the setMethod line just after the setClass one, as in the following example: setClass(DB, representation(flag.grid = logical, ndim = numeric, x0 = numeric, dx = numeric, nx = numeric, locators =character,items = data.frame)) setMethod(show,DB,function(object) DB.print(object)) setMethod(print,signature(x=DB),function(x,...) DB.print(x)) setMethod(plot,signature(x=DB),function(x,y,...) DB.plot(x)) setMethod([ ,signature(x=DB),db0.getindex) setMethod([-,signature(x=DB),db0.setindex) setMethod($ ,signature(x=DB),db0.get) setMethod($-,signature(x=DB),db0.set) As one can notice, I use the same mechanism for SHOW, PLOT and PRINT. Finally I created the package and imagined to use it using library statement Surprisingly, when I used the library statement, the program tells me: standardGeneric for print defined from package base standardGeneric for plot defined from package base and creates two objects in the .GlobalEnv, namely plot and print with the following contents: print standardGeneric for print defined from package base function (x, ...) standardGeneric(print) environment: 0xa275c70 Methods may be defined for arguments: x Use showMethods(print) for currently available ones. Nothing similar for show although my use of setMethod is the same. I see a main difference as show belongs to the methods library whereas the two other belong to the base library. Bu t I could not see how to avoid a user of my library to have these message and the two objects created. I am allowed to set the method as I did (I think that I read something telling me that I could not do it with methods of the base library). Otherwiser how can I define the function DB.print as the required method for printing objects belonging to the DB class. Thank in advance for you help. -- Didier RENARD Centre de Geosciences / Geostatistique Ecole des Mines de Paris 35 Rue St Honore 77300 Fontainebleau Tel: (1) 64 69 47 80 Fax: (1) 64 69 47 05 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Problems compiling a simple source package on MacOS X
Simon Urbanek wrote: In addition, please consider looking at R-SIG-Mac where Mac-related discussion takes place and this has been discussed before (stuffing the error in google gives exactly the relevant hit on the list...) Thank you, that was helpful. I'll try upgrading to Xcode 2.5. Very sorry to have bothered the list with a Google-able problem. I did try Googling first, but I was using /usr/bin/libtool: internal link edit command failed as the search term rather than the ld error above it. When I did the latter, I immediately found the post you referred to. I'll see if this fixes the problem. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Problem with S3 to S4 transition
Hi Renard -- On 03/16/2010 05:26 AM, Renard Didier wrote: Hello to everybody I am developing a package using R and have the following problem: I used to work in a mixture of S3 and S4 mechanism environment: as a matter of fact, I used to define my classes (say DB for illustration) using the setClass function (with representation field), and I was using the S3 implicit mechanism writing the functions: print.DB and plot.DB. Recently, I read some interesting papers on the use of S4 mechanism and was convinced that I would have some benefit in turning everything on S4 formalism. This is the reason why I simply renamed my previous functions into DB.print and DB.plot (by analogy with other functions where the Class name is the leading part of the name). My idea was to use the setMethod principle to set the DB.print function as the function for the print method on the DB class. Therefore, in the .First.Lib file of my package, I introduced the setMethod line just after the setClass one, as in the following example: setClass(DB, representation(flag.grid = logical, ndim = numeric, x0 = numeric, dx = numeric, nx = numeric, locators =character,items = data.frame)) setMethod(show,DB,function(object) DB.print(object)) setMethod(print,signature(x=DB),function(x,...) DB.print(x)) setMethod(plot,signature(x=DB),function(x,y,...) DB.plot(x)) setMethod([ ,signature(x=DB),db0.getindex) setMethod([-,signature(x=DB),db0.setindex) setMethod($ ,signature(x=DB),db0.get) setMethod($-,signature(x=DB),db0.set) 'print' is not needed for S4 objects, 'show' does the job. Normally one does not place setClass() or setMethod() in .First.lib, but uses them like any other function definition (e.g., in a file methods-DB.R). It can sometimes be important to use a Collates: field in the DESCRIPTION file so that classes are defined before methods that dispatch on them. As one can notice, I use the same mechanism for SHOW, PLOT and PRINT. Finally I created the package and imagined to use it using library statement Surprisingly, when I used the library statement, the program tells me: standardGeneric for print defined from package base standardGeneric for plot defined from package base and creates two objects in the .GlobalEnv, namely plot and print with the following contents: print standardGeneric for print defined from package base function (x, ...) standardGeneric(print) environment: 0xa275c70 Methods may be defined for arguments: x Use showMethods(print) for currently available ones. Nothing similar for show although my use of setMethod is the same. I see a main difference as show belongs to the methods library whereas the two other belong to the base library. Bu t I could not see how to avoid a user of my library to have these message and the two objects created. 'show' is already a generic, defined in methods, so a generic does not need to be created. plot is a regular R function, so setMethod(plot, ...) has to create a generic and then associate your method with it. When setMethod(plot, ...) is defined as suggested above, the new generic is generated when the package is installed (not loaded, so the message creating a new generic is only presented at installation) and placed in the package environment (e.g., ls(name=package:pkgA)) and not .GlobalEnv. Explicitly calling setGeneric(plot) creates the generic without the information message. Consider using a NAMESPACE (and .onLoad() rather than .FirstLib). Best, Martin I am allowed to set the method as I did (I think that I read something telling me that I could not do it with methods of the base library). Otherwiser how can I define the function DB.print as the required method for printing objects belonging to the DB class. Thank in advance for you help. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Martin Morgan Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M1 B861 Phone: (206) 667-2793 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel