[Rd] escaping 'comment' chars in example sections
Dear list, I've noticed that, when writing examples in an Rd file, you need to escape the '%' character, even if it is valid R code. I can see maybe this is the intended behaviour, but I found it a bit surprising, and leads to cryptic error messages from 'R CMD check'. The relevant section in the "writing R extensions" manual isn't clear on that point either. To reproduce the behaviour I'm talking about, you can run this snippet: ## library(tools) Rd2ex(parse_Rd(textConnection(" \\title{a} \\name{b} \\examples{ 'a' %in% letters } "))) ## You can see that everything from '%' on is dropped from the output, as a regular Rd comment. Should this be mentioned in the manual? cheers, fabio. > R.version _ platform x86_64-unknown-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status Patched major 2 minor 11.0 year 2010 month 05 day19 svn rev52043 language R version.string R version 2.11.0 Patched (2010-05-19 r52043) -- Antonio Fabio Di Narzo, PhD. Swiss Institute for Bioinformatics - Bioinformatics Core Facility Office 2029, Génopode, Quartier Sorge CH-1015 Lausanne, Switzerland Tel: +41 21 692 4087 Fax: +41 21 692 4065 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] escaping 'comment' chars in example sections
Antonio, Fabio Di Narzo wrote: Dear list, I've noticed that, when writing examples in an Rd file, you need to escape the '%' character, even if it is valid R code. I can see maybe this is the intended behaviour, but I found it a bit surprising, and leads to cryptic error messages from 'R CMD check'. The relevant section in the "writing R extensions" manual isn't clear on that point either. It says "... Comments run from a percent symbol % to the end of the line in all types of text (as on the first line of the load example). Because backslashes, braces and percent symbols have special meaning, to enter them into text sometimes requires escapes using a backslash. In general balanced braces do not need to be escaped, but percent symbols always do. For the complete list of macros and rules for escapes, see “Parsing Rd files”. " I think that is clear on percent symbols. The situation for backslashes and braces is more complicated, and you need to follow the link for those rules. Duncan Murdoch To reproduce the behaviour I'm talking about, you can run this snippet: ## library(tools) Rd2ex(parse_Rd(textConnection(" \\title{a} \\name{b} \\examples{ 'a' %in% letters } "))) ## You can see that everything from '%' on is dropped from the output, as a regular Rd comment. Should this be mentioned in the manual? cheers, fabio. R.version _ platform x86_64-unknown-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status Patched major 2 minor 11.0 year 2010 month 05 day19 svn rev52043 language R version.string R version 2.11.0 Patched (2010-05-19 r52043) __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] S4 method defined but not used
Dear R developers, I am having a slightly weird issue with a S4 method defined in my package adegenet 1.2-4, with R 2.11.0. As far as I know, the problem is new, and the code implementing the method has not changed for more than a year and worked well so far. The problem is the following. I define, in the package, a method "[" for the S4 class 'genind'. The method's definition is: setMethod("[", signature(x="genind", i="ANY", j="ANY", drop="ANY"), function(x, i, j, ..., loc=NULL, treatOther=TRUE, drop=FALSE) { ... ## code of the function }) When sourcing the code directly from R, this method is found and used normally. However, when loading the package, the method does not seem to be "found" any longer by the dispatcher. For instance, here is an error I get: ### R code > library(adegenet) > data(nancycats) # nancycat is a S4 object with class 'genind' > class(nancycats) [1] "genind" attr(,"package") [1] "adegenet" > nancycats[1] Error in nancycats[1] : object of type 'S4' is not subsettable # "[" IS NOT USED HERE ### end R code And still, the method is defined in the environment: ### R code > showMethods("[", class="genind") Function: [ (package base) x="genind" > findMethods("[", classes="genind")$genind Method Definition: function (x, i, j, ..., drop = FALSE) { .local <- function (x, i, j, ..., loc = NULL, treatOther = TRUE, drop = FALSE) { if (missing(i)) i <- TRUE if (missing(j)) j <- TRUE pop <- NULL ... # rest of the code of the function ### end R code findMethods and showMethods find the method. However, getMethod doesn't: ### R code > getMethod("[","genind") Error in getMethod("[", "genind") : No method found for function "[" and signature genind ### end R code Now, if I just try the same thing after sourcing the code of the method manually, everything works fine. showMethods then reads: ### R code > showMethods("[", classes="genind") Function: [ (package base) x="genind" x="genind", i="ANY", j="ANY", drop="ANY" x="genind", i="numeric", j="missing", drop="missing" (inherited from: x="genind", i="ANY", j="ANY", drop="ANY") ### end R code My R version/session is: ### R code > R.version _ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major 2 minor 11.0 year 2010 month 04 day22 svn rev51801 language R version.string R version 2.11.0 (2010-04-22) > sessionInfo() R version 2.11.0 (2010-04-22) i686-pc-linux-gnu locale: [1] LC_CTYPE=en_GB.utf8 LC_NUMERIC=C [3] LC_TIME=en_GB.utf8LC_COLLATE=en_GB.utf8 [5] LC_MONETARY=C LC_MESSAGES=en_GB.utf8 [7] LC_PAPER=en_GB.utf8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_GB.utf8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] adegenet_1.2-4 MASS_7.3-5 loaded via a namespace (and not attached): [1] graph_1.26.0 phylobase_0.5 tcltk_2.11.0 tools_2.11.0 ### end R code R was compiled from the sources. All packages are up-to-date (as of the 21 May 2010). My system is a Ubuntu 10.04 (32 bits), with kernel 2.6.31-20-generic. I could not reproduce the problem using R 2.11.0 on Windows Vista, or on Debian testing (R 2.11.0 compiled from the sources). The package adegenet does not have a namespace. The error arises whether using a field 'Collate' in DESCRIPTION, or not. I checked that the source file is indeed sourced when loading the package: it is. The method "[" is not defined by any other package for 'genind' objects. I would be pleased to get any piece of insight, advice, or explanation for this issue. Thanks in advance for your time. Best regards, Thibaut Jombart. -- ## Dr Thibaut JOMBART MRC Centre for Outbreak Analysis and Modelling Department of Infectious Disease Epidemiology Imperial College - Faculty of Medicine St Mary’s Campus Norfolk Place London W2 1PG United Kingdom Tel. : 0044 (0)20 7594 3658 t.jomb...@imperial.ac.uk http://sites.google.com/site/thibautjombart/ http://adegenet.r-forge.r-project.org/ __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] dyn.load() strange behavior
Hello, I am observing the following strange behavior when I try to load a shared library using dyn.load() under Linux... The library foo.so refers to a symbol in another package bar (with shared library bar.so), I get: dyn.load('foo.so') # error message because I forgot to load bar library(bar) # so I fix it dyn.load('foo.so') # works this time and everything is fine But, if restart my R session and do it "right" the second time there is a surprise: library(bar) dyn.load('foo.so') # fails library(bar) # just to be sure? dyn.load('foo.so) # fails again dyn.load('/usr/local/lib64/library/bar/lib/libbar.so') # just to be really sure? dyn.load('foo.so') In other words, it is possible to load foo.so, but only after a failed attempt. If I remember to load the required package bar I cannot load the depenent library foo.so. Any ideas? Thanks, Dominick [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel