Re: [Rd] require( foo (= 2.1) )
Hi Romain, not that I have any authority here, but wouldn't your suggestion (which I think could be very useful) be more powerful if it were accompanied by a patch that could be applied to the R sources? Best wishes Wolfgang Huber EMBL http://www.embl.de/research/units/genome_biology/huber On 28/05/10 19:25, Romain Francois wrote: Hello, I often find myself writing code like : if( require( foo ) compareVersion( packageDescription( foo)[[Version]], 2.1 ) 0 ){ # code that uses version 2.1 of foo } else { stop( could not load version = 2.1 of foo ) } Would it make sense to include something like this in require, library, etc ... require( foo (= 2.1) ) require( foo, minimal.version = 2.1 ) I know we can use Depends: foo (= 2.1) in a package DESCRIPTION file, but that does not work for loose dependencies, when package bar works better with foo but can still work fine without, or when not making a package. Romain -- __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] S4 dispatch for .DollarNames (utils)
Dear all, thank your for this discussion - I had been wondering how to get the completion with my S4 class, but it didn't bother me enough to dig into things. The workaround/hack that *does* work now, I believe, is to insert a dummy S3 class into the mix and define the S3 .DollarNames method for it. Example: setOldClass(foo3) .DollarNames.foo3 - function(x, pattern)bar My question here is: what is the dummy class needed for? I have a few S3 methods for my S4 class (rbind.hyperSpec, cbind.hyperSpec, and now .DollarNames.hyperSpec). They seem to work just fine without first setting up a dummy S3 class that is then used in the contains of the S4 definition. Any pitfalls with that? Claudia -- Claudia Beleites Dipartimento dei Materiali e delle Risorse Naturali Università degli Studi di Trieste Via Alfonso Valerio 6/a I-34127 Trieste phone: +39 0 40 5 58-37 68 email: cbelei...@units.it __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] S4 dispatch for .DollarNames (utils)
Claudia, Your S3 methods will be selected for objects from hyperSpec, but not for S4 classes that inherit from that class (that have contains=hyperSpec in their definition). The S3 method dispatch has been fixed to recognize S4 classes that inherit from an S3 class, foo3 in my example. The plan is to fix that for the next release, and have S3 dispatch behave for all S4 objects, not just those that inherit from an S3 class. Meanwhile, the dummy class is needed. On 5/30/10 8:08 AM, Claudia Beleites wrote: Dear all, thank your for this discussion - I had been wondering how to get the completion with my S4 class, but it didn't bother me enough to dig into things. The workaround/hack that *does* work now, I believe, is to insert a dummy S3 class into the mix and define the S3 .DollarNames method for it. Example: setOldClass(foo3) .DollarNames.foo3 - function(x, pattern)bar My question here is: what is the dummy class needed for? I have a few S3 methods for my S4 class (rbind.hyperSpec, cbind.hyperSpec, and now .DollarNames.hyperSpec). They seem to work just fine without first setting up a dummy S3 class that is then used in the contains of the S4 definition. Any pitfalls with that? Claudia __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] S4 dispatch for .DollarNames (utils)
John, Thank your for the explanation! Claudia -- Claudia Beleites Dipartimento dei Materiali e delle Risorse Naturali Università degli Studi di Trieste Via Alfonso Valerio 6/a I-34127 Trieste phone: +39 0 40 5 58-37 68 email: cbelei...@units.it __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] require( foo (= 2.1) )
Hi, Sure. I could and I would provide a patch. Since this is more of a nice to have, I wanted to first find out whether others would find it useful, and also if such a patch would have chances to get accepted by one of R-core members. Sometimes patches I or others provide upfront are not accepted. I'm not complaining about it, it is always an opportunity to learn something ... Romain Le 30/05/10 14:49, Wolfgang Huber a écrit : Hi Romain, not that I have any authority here, but wouldn't your suggestion (which I think could be very useful) be more powerful if it were accompanied by a patch that could be applied to the R sources? Best wishes Wolfgang Huber EMBL http://www.embl.de/research/units/genome_biology/huber On 28/05/10 19:25, Romain Francois wrote: Hello, I often find myself writing code like : if( require( foo ) compareVersion( packageDescription( foo)[[Version]], 2.1 ) 0 ){ # code that uses version 2.1 of foo } else { stop( could not load version = 2.1 of foo ) } Would it make sense to include something like this in require, library, etc ... require( foo (= 2.1) ) require( foo, minimal.version = 2.1 ) I know we can use Depends: foo (= 2.1) in a package DESCRIPTION file, but that does not work for loose dependencies, when package bar works better with foo but can still work fine without, or when not making a package. Romain -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/99bz5D : highlight 0.1-9 |- http://bit.ly/9CQ66r : RMetrics 2010 `- http://bit.ly/bklUXt : RcppArmadillo 0.2.1 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Bug with ..0
This function call returns 3 but should return 32. ..0 has no special significance in R as far I know yet it seems to be acting as if it were ..1 . Comments? ff - function(..0, ...) ..0 ff(32, 3) [1] 3 R.version.string [1] R version 2.11.0 Patched (2010-04-26 r51822) win.version() [1] Windows Vista (build 6002) Service Pack 2 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Bug with ..0
On 30/05/2010 3:13 PM, Gabor Grothendieck wrote: This function call returns 3 but should return 32. ..0 has no special significance in R as far I know yet it seems to be acting as if it were ..1 . Comments? Actually, ..0 is a reserved symbol. (This is just barely documented in the R Language Defn, with more detail in R Internals.) It stands for the zeroth element of ... That definition makes no sense (indexing of ... starts at 1), so we should probably generate an error when you use it, and perhaps when you try to redefine it by using it as an argument. But this is really a case of you doing something you shouldn't, and the error handling not slapping you on the wrist. Duncan Murdoch ff - function(..0, ...) ..0 ff(32, 3) [1] 3 R.version.string [1] R version 2.11.0 Patched (2010-04-26 r51822) win.version() [1] Windows Vista (build 6002) Service Pack 2 __ 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] Bug with ..0
Note that ?Reserved lists ..1, ..2, to ..9 but does not list ..0. Also, why is it reserved? What is the future intended use? On Sun, May 30, 2010 at 3:40 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 30/05/2010 3:13 PM, Gabor Grothendieck wrote: This function call returns 3 but should return 32. ..0 has no special significance in R as far I know yet it seems to be acting as if it were ..1 . Comments? Actually, ..0 is a reserved symbol. (This is just barely documented in the R Language Defn, with more detail in R Internals.) It stands for the zeroth element of ... That definition makes no sense (indexing of ... starts at 1), so we should probably generate an error when you use it, and perhaps when you try to redefine it by using it as an argument. But this is really a case of you doing something you shouldn't, and the error handling not slapping you on the wrist. Duncan Murdoch ff - function(..0, ...) ..0 ff(32, 3) [1] 3 R.version.string [1] R version 2.11.0 Patched (2010-04-26 r51822) win.version() [1] Windows Vista (build 6002) Service Pack 2 __ 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] Bug with ..0
On 30/05/2010 3:44 PM, Gabor Grothendieck wrote: Note that ?Reserved lists ..1, ..2, to ..9 but does not list ..0. Which version are you looking at? Mine says ‘..1’, ‘..2’ etc, In fact, the code just looks for the pattern of two dots followed by something that can be converted to a long; see isDDName in src/main/dstruct.c. Also, why is it reserved? What is the future intended use? As far as I know, there is none. It is reserved simply because it follows the pattern of ..n. It would not be hard to make ..0 specially unreserved, but what would be the point? Duncan Murdoch On Sun, May 30, 2010 at 3:40 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 30/05/2010 3:13 PM, Gabor Grothendieck wrote: This function call returns 3 but should return 32. ..0 has no special significance in R as far I know yet it seems to be acting as if it were ..1 . Comments? Actually, ..0 is a reserved symbol. (This is just barely documented in the R Language Defn, with more detail in R Internals.) It stands for the zeroth element of ... That definition makes no sense (indexing of ... starts at 1), so we should probably generate an error when you use it, and perhaps when you try to redefine it by using it as an argument. But this is really a case of you doing something you shouldn't, and the error handling not slapping you on the wrist. Duncan Murdoch ff - function(..0, ...) ..0 ff(32, 3) [1] 3 R.version.string [1] R version 2.11.0 Patched (2010-04-26 r51822) win.version() [1] Windows Vista (build 6002) Service Pack 2 __ 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] Location of source code for readline()
A few days ago on R-help I asked about a cross-platform timeout version of readline(). Some suggestions, but only partial joy so far. I can get the Gnu bash 'read -t ...' to work in Windows by using the 'bash -c ' construct, but then R's system() function does not seem to allow this to pass through. Similarly a Perl and Free Pascal routine that I tried, the latter being a single executable that did the prompt and the timeout. (I can send code offline if anyone interested -- not fully protected against bad inputs, however.) Now I'm wondering where the code for readline is located in the R source. I've tracked as far as the 'do_readln' in names.c, but now want to find the actual code to see if I can patch it, though I am a real novice in C. Suggestions welcome. My application, FYI, is to have a script that will display something, and wait for a keypress (for readline it seems to need the Enter key) but timeout after a preset number of seconds. The setTimeLimit almost works -- but not for readline. I'm thinking of a modified readline like readline(prompt='Do you want to continue?', timeout=6). Note that the issue seems to be Windows. I haven't a Mac to try, but Linux can be made to function by various methods at the top. Sigh. JN __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Bug with ..0
On Sun, May 30, 2010 at 4:31 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: As far as I know, there is none. It is reserved simply because it follows the pattern of ..n. It would not be hard to make ..0 specially unreserved, but what would be the point? Here is the case I had in mind. The gsubfn function in the gsubfn package is like gsub except the replacement string can be a replacement function such that it passes the back references in the pattern as successive args to the function. Here it would pass two args to the function represented by (.) and (.) in the regular expression and then replace the match with the output of the function which in this case is the sum of the digits surrounded with angle brackets: gsubfn((.)#(.), function(...) paste0(, as.numeric(..1) + as.numeric(..2), ), 1#2 3#4) [1] 3 7 There is also an option to pass the entire match followed by the back references to the user function. In that case it would be nice for the user to be able to write the user function as follows where ..0 means the entire match. Here we replace the match with an angle bracket, the entire match, an equal sign, the sum and an end angle bracket: gsubfn((.)#(.), function(..0, ...) paste0(, ..0, =, as.numeric(..1) + as.numeric(..2), ), 1#2 3#4) [1] 1#2=3 3#4=7 Note the use of ..0 to mean the entire match is in this context and how natural it is. To do the above the best would be if we could just use ..0 as an ordinary variable. Barring that we could replace all occurrences of ..0 with X..0, say, so that: function(..0, ...) list(..0, ..1) would be transformed to the function function(X..0, ...) list(X..0, ..1) and that could work now but that would depend on R not being changed in the future to issue an error when a function such as f above that uses ..0 is created. (Although not illustrated here there is also a formula notation which allows one to specify the function as a formula whose body is taken to be the formula's RHS and the args are reconstructed from the RHS free variables. In that case the ..0 notation becomes even more useful.) __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Location of source code for readline()
On 2010-05-30 15:33, Prof. John C Nash wrote: A few days ago on R-help I asked about a cross-platform timeout version of readline(). Some suggestions, but only partial joy so far. I can get the Gnu bash 'read -t ...' to work in Windows by using the 'bash -c ' construct, but then R's system() function does not seem to allow this to pass through. Similarly a Perl and Free Pascal routine that I tried, the latter being a single executable that did the prompt and the timeout. (I can send code offline if anyone interested -- not fully protected against bad inputs, however.) Now I'm wondering where the code for readline is located in the R source. I've tracked as far as the 'do_readln' in names.c, but now want to find the actual code to see if I can patch it, though I am a real novice in C. Suggestions welcome. My application, FYI, is to have a script that will display something, and wait for a keypress (for readline it seems to need the Enter key) but timeout after a preset number of seconds. The setTimeLimit almost works -- but not for readline. I'm thinking of a modified readline like readline(prompt='Do you want to continue?', timeout=6). Note that the issue seems to be Windows. I haven't a Mac to try, but Linux can be made to function by various methods at the top. Sigh. JN I can't help with your project, but check scan.c for do_readln. -Peter Ehlers __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel