Re: [Rd] S4 classes in existing packages
Jeff Enos schrieb: >R-devel, > >I'm interested in looking at some examples of existing R packages that >rely heavily on S4 classes to get a feel for varying styles and >package organization techniques. Could you recommend any packages >that might serve as a good starting point? > >Thanks in advance, > >Jeff > > our packages distr, distrEx, distrSim, distrTEst and RandVar are based on S4 classes and methods. hth Matthias >__ >R-devel@r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-devel > > -- StaMatS - Statistik + Mathematik Service Dipl.Math.(Univ.) Matthias Kohl www.stamats.de __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] import of Namespaces
Dear R devels, let's say I have three packages "pkg1", "pkg2" and "pkg3" which all contain new S4 classes and methods. Where "pkg3" depends on "pkg2" and "pkg2" depends on "pkg1". Moreover, all three packages have namespaces. 1) I use ".onLoad <- function(lib, pkg) require(methods)". Do I also have to import the namespace of "methods" package? 2) If I use import("pkg1") in the namespace of "pkg2", does this also (correctly) import the S4 classes and methods of "pkg1"? Or do I explicitly have to use importClassesFrom resp. importMethodsFrom? 3) If I import the Namespace of "pkg2" in "pkg3", where the namespace of "pkg2" has import("pkg1") (or maybe importClassesFrom, importMethodsFrom) and I also want to use S4 classes and methods of "pkg1" in "pkg3". Is it sufficient to have import("pkg2") in the Namespace of "pkg3" or do I need import("pkg1") and import("pkg2")? Many thanks for your help and advice Matthias -- StaMatS - Statistik + Mathematik Service Dipl.Math.(Univ.) Matthias Kohl www.stamats.de __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] problems with initialize-method, difference between Win XP & Linux
Dear R devels, I have some questions concerning the use of "initialize". Situation: There are two packages "S4pkg1" and "S4pkg2" which include S4 classes and methods where the first one contains a new S4 class "S4pkg1Class". Then, in "S4pkg2" there is a new S4 class "S4pkg2Class" which has a slot of class "S4pkg1Class". Both packages have a namespace where I use exportClasses("S4pkg1Class") in the namespace of "S4pkg1" and import("S4pkg1") in the namespace of "S4pkg2". # 1. Solution: I provide a prototype argument in the definition of "S4pkg1Class" and use new("S4pkg1Class") in the prototype of "S4pkg2Class". Then, everything works fine under Windows XP and (Suse 9.3) Linux using R 2.2.0 and R 2.3.0 devel; i.e., calling "new("S4pkg2Class")" returns an object of class "S4pkg2Class" and the slot of class "S4pkg1Class" is filled with the corresponding prototype. # 2. Solution: I don't provide a prototype argument in the definition of "S4pkg1Class". Instead, I define an "initialize"-method for class "S4pkg1Class" with default arguments for the slots of "S4pkg1Class" and again I use "new("S4pkg1Class")" in the prototype of class "S4pkg2Class". Moreover, I use exportMethods("initialize") in the namespace of package "S4pkg1". Then, everything seems to work fine (at least on my PC) under Windows XP using R 2.2.0 and R 2.3.0 devel; i.e., calling "new("S4pkg2Class")" returns an object of class "S4pkg2Class" where the slot of class "S4pkg1Class" now is filled with the default object generated by the initialize-method of class "S4pkg1Class". However, under (Suse 9.3) Linux using R 2.2.0 and R 2.3.0 devel "new("S4pkg2Class")" returns an object of class "S4pkg2Class" where the slot of class "S4pkg1Class" is not filled with the default object generated by the initialize-method of class "S4pkg1Class" but with a "default-protoype" (slots are filled with "numeric(0)", "character(0)", ...). Can someone confirm this behavior? The sources of two sample packages can be found under: http://www.stamats.de/S4pkg1_0.1-1.tar.gz and http://www.stamats.de/S4pkg2_0.1-1.tar.gz After installation please try: require(S4pkg1) new("S4pkg1Class") # o.k., default values of initialize are used require(S4pkg2) new("S4pkg2Class") # is slot "pkg1" filled with the output of new("S4pkg1Class") given above??? Why does this work under Windows XP but not under (Suse 9.3) Linux? Am I doing something wrong - or is this a bug? Many thanks for any help! Matthias -- StaMatS - Statistik + Mathematik Service Dipl.Math.(Univ.) Matthias Kohl www.stamats.de __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] S4 default initialization: unwanted NULL
you might need a call to "setOldClass"; see Section "Register or Convert?" of the corresponding help page. Matthias Seth Falcon schrieb: >The default initialization for slots of class "factor" and >"data.frame" gives NULL. This seems odd, since those slots can't ever >be set to NULL by the user. I would expect zero-length instances of >factor and data.frame. > >Here is an example: > >setClass("FOO", representation(a="factor", b="data.frame", c="numeric")) >[1] "FOO" > > >>ff <- new("FOO") >>ff >> >> >An object of class "FOO" >Slot "a": >NULL > >Slot "b": >NULL > >Slot "c": >numeric(0) > > >sessionInfo() >R version 2.3.0, 2005-12-26, powerpc-apple-darwin8.3.0 > >attached base packages: >[1] "tools" "methods" "stats" "graphics" "grDevices" "utils" >[7] "datasets" "base" > > >Slot c is initialized as I was expecting. > >+ seth > >__ >R-devel@r-project.org mailing list >https://stat.ethz.ch/mailman/listinfo/r-devel > > -- StaMatS - Statistik + Mathematik Service Dipl.Math.(Univ.) Matthias Kohl Gottlieb-Keim-Straße 60 95448 Bayreuth Phone: +49 921 50736 457 E-Mail: [EMAIL PROTECTED] www.stamats.de __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] How to overload the assignment operator?
are you looking for "setReplaceMethod"? hth Matthias Jens Oehlschlägel wrote: > Dear all, > > what is the proper way to make the assignment operator generic and define > methods depending on the class of the assigned value? > > Best regards > > > Jens Oehlschlägel > > P.S. I vaguely remember that this was possible in S+. In R I tried to no > avail: > > # using this like h<-1:3 gives Error: in `<-.default`(h, 1:3) : invalid > (do_set) left-hand side to assignment > "<-.default" <- get("<-") > > # using this does fail on subassignments like: h <- 1:3 ; h[1] <- 7 (h > still is 1:3) > "<-.default" <- function(x, value){ > assign(deparse(substitute(x)), value, parent.frame()) > invisible(x) > } > > # this seems to work > "<-" <- function(x, value){ > UseMethod("<-", value) > } > > # whenever the assigned value has class 'ff' I want to do execute something > like > "<-.ff" <- function(x, value){ > y <- clone(value) > assign(deparse(substitute(x)), y, parent.frame()) > y > } > > > >> version >> >_ > platform i386-pc-mingw32 > arch i386 > os mingw32 > system i386, mingw32 > status > major 2 > minor 6.0 > year 2007 > month 10 > day03 > svn rev43063 > language R > version.string R version 2.6.0 (2007-10-03) > > -- > > __ > 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] small bug in panel.cor in example for pairs?
Dear all, in the Example section of pairs there is panel.cor <- function(x, y, digits=2, prefix="", cex.cor) { usr <- par("usr"); on.exit(par(usr)) par(usr = c(0, 1, 0, 1)) r <- abs(cor(x, y)) txt <- format(c(r, 0.123456789), digits=digits)[1] txt <- paste(prefix, txt, sep="") if(missing(cex.cor)) cex <- 0.8/strwidth(txt) text(0.5, 0.5, txt, cex = cex * r) } Shouldn't the last two lines read if(missing(cex.cor)) cex.cor <- 0.8/strwidth(txt) text(0.5, 0.5, txt, cex = cex.cor * r) ? Best, Matthias -- Dr. Matthias Kohl Mathematical Statistics University of Bayreuth __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] d_fontdb.d, g_her_glyph.d
Dear Developers, I'm updating my R installation via svn (currently: Revision 44626). For some time now (sorry don't know the exact revision number) make for R devel yields the following error make[4]: *** Keine Regel vorhanden, um das Target »../../../src/include/R_ext/GraphicsBase.h«, benötigt von »g_fontdb.o«, zu erstellen. Schluss. (translation: no rule to make target ... needed from ...) The file "g_fontdb.d" (and also g_her_glyph.d) has the last line ../../../src/include/R_ext/GraphicsBase.h Is this line obligate due to 1) in https://svn.r-project.org/R-dev-web/trunk/270update.txt ? At least, if I remove this last line in these two files make runs without an error. Is there another explanation for this error? Thanks for your help! Matthias # My configure output is: R is now configured for i686-pc-linux-gnu Source directory: . Installation directory:/usr/local C compiler:gcc -std=gnu99 -g -O2 Fortran 77 compiler: g77 -g -O2 C++ compiler: g++ -g -O2 Fortran 90/95 compiler:g77 -g -O2 Obj-C compiler: Interfaces supported: X11, tcltk External libraries:readline Additional capabilities: PNG, JPEG, iconv, MBCS, NLS, cairo Options enabled: shared BLAS, R profiling, Java Recommended packages: yes # my system is: (sessionInfo from R version 2.6.2 Patched (2008-02-10 r44423)) i686-pc-linux-gnu locale: LC_CTYPE=de_DE.UTF-8;LC_NUMERIC=C;LC_TIME=de_DE.UTF-8;LC_COLLATE=de_DE.UTF-8;LC_MONETARY=de_DE.UTF-8;LC_MESSAGES=de_DE.UTF-8;LC_PAPER=de_DE.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=de_DE.UTF-8;LC_IDENTIFICATION=C -- Dr. Matthias Kohl www.stamats.de __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] d_fontdb.d, g_her_glyph.d
now, it works ... Thanks! Prof Brian Ripley wrote: > On Wed, 27 Feb 2008, Matthias Kohl wrote: > >> Dear Developers, >> >> I'm updating my R installation via svn (currently: Revision 44626). For >> some time now (sorry don't know the exact revision number) make for R >> devel yields the following error > > You need to start a clean build: you are updating from a rather old one. > Try something like > > make distclean > ./configure > make > > In some cases (and this was one) if you update every day it may work, > but in a few cases you will need to rebuild from scratch after a change. > >> >> make[4]: *** Keine Regel vorhanden, um das Target >> »../../../src/include/R_ext/GraphicsBase.h«, >> benötigt von »g_fontdb.o«, zu erstellen. Schluss. >> >> (translation: no rule to make target ... needed from ...) >> >> The file "g_fontdb.d" (and also g_her_glyph.d) has the last line >> ../../../src/include/R_ext/GraphicsBase.h >> >> Is this line obligate due to 1) in >> https://svn.r-project.org/R-dev-web/trunk/270update.txt >> ? >> >> At least, if I remove this last line in these two files make runs >> without an error. >> Is there another explanation for this error? >> >> Thanks for your help! >> Matthias >> >> # >> My configure output is: >> R is now configured for i686-pc-linux-gnu >> >> Source directory: . >> Installation directory:/usr/local >> >> C compiler:gcc -std=gnu99 -g -O2 >> Fortran 77 compiler: g77 -g -O2 >> >> C++ compiler: g++ -g -O2 >> Fortran 90/95 compiler:g77 -g -O2 >> Obj-C compiler: >> >> Interfaces supported: X11, tcltk >> External libraries:readline >> Additional capabilities: PNG, JPEG, iconv, MBCS, NLS, cairo >> Options enabled: shared BLAS, R profiling, Java >> >> Recommended packages: yes >> >> # >> my system is: (sessionInfo from R version 2.6.2 Patched (2008-02-10 >> r44423)) >> i686-pc-linux-gnu >> >> locale: >> LC_CTYPE=de_DE.UTF-8;LC_NUMERIC=C;LC_TIME=de_DE.UTF-8;LC_COLLATE=de_DE.UTF-8;LC_MONETARY=de_DE.UTF-8;LC_MESSAGES=de_DE.UTF-8;LC_PAPER=de_DE.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=de_DE.UTF-8;LC_IDENTIFICATION=C >> >> >> >> -- >> Dr. Matthias Kohl >> www.stamats.de >> >> __ >> R-devel@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel >> > -- Dr. Matthias Kohl www.stamats.de __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] \S4method in combination with "[" and "[<-"
Dear developers, We want to use "\S4method" to document new S4-methods for "[" and "[<-". We use this for other functions/methods and it works without any problem, but in case of "[" and "[<-" we didn't manage to bring this to work. The problem occurs in the development version of our package "distrSim" which can be found under http://r-forge.r-project.org/R/?group_id=87. The warning we obtain is Bad \usage lines found in documentation object 'Subsetting-methods': \S4method{[}{SeqDataFrames}(x, i, j, k, drop = FALSE) \S4method{[<-}{SeqDataFrames}(x, i, j, k, value) Of course, we tried several different possibilities but with no success. Does someone know a package which shows a use case for this situation? I looked in several packages but could not found any. Thanks for your help! Matthias -- Dr. Matthias Kohl www.stamats.de __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] \S4method in combination with "[" and "[<-"
Hello Robin, thanks for your solution! Other solutions I know: 1. In the Matrix package - version 0.999375-9. See Subassign-methods.Rd and Xtrct-methods.Rd. 2. The other possibility, which we use in some situations and which for instance is used in package Biobase (e.g., S4-class eSet), is to document methods in the Rd-files of the corresponding S4-classes. However, both solutions are without using "\S4method". Best, Matthias Robin Hankin wrote: Hello Matthias I too struggled with this for a long long time. I'm not sure if this answers your question, but Brobdingnag_1.1-2.tar.gz is clean under R-2.7.0, and this package includes S4 methods for extract/replace. Extract.Rd in the package doesn't use \S4method; also, I couldn't figure out how to include a "usage" section without R CMD check throwing a wobbly. Extract.Rd is not ideal, but seems to work in practice: the user types ?"[.brob" and gets some support, but it would have been better to have an explicit usage section too. best wishes rksh On 21 May 2008, at 09:23, Matthias Kohl wrote: Dear developers, We want to use "\S4method" to document new S4-methods for "[" and "[<-". We use this for other functions/methods and it works without any problem, but in case of "[" and "[<-" we didn't manage to bring this to work. The problem occurs in the development version of our package "distrSim" which can be found under http://r-forge.r-project.org/R/?group_id=87. The warning we obtain is Bad \usage lines found in documentation object 'Subsetting-methods': \S4method{[}{SeqDataFrames}(x, i, j, k, drop = FALSE) \S4method{[<-}{SeqDataFrames}(x, i, j, k, value) Of course, we tried several different possibilities but with no success. Does someone know a package which shows a use case for this situation? I looked in several packages but could not found any. Thanks for your help! Matthias -- Dr. Matthias Kohl www.stamats.de __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Robin Hankin Uncertainty Analyst and Neutral Theorist, National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 -- Dr. Matthias Kohl www.stamats.de __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] \S4method in combination with "[" and "[<-"
Dear Kurt, I tried your proposal. It also led to Bad \usage lines found in documentation object 'Subsetting-methods': \S4method{[}{SeqDataFrames}(x, i, j, k, drop = FALSE) \S4method{[}{SeqDataFrames}(x, i, j, k) <- value My sessionInfo: R version 2.7.0 Patched (2008-05-20 r45741) i686-pc-linux-gnu locale: LC_CTYPE=de_DE.UTF-8;LC_NUMERIC=C;LC_TIME=de_DE.UTF-8;LC_COLLATE=de_DE.UTF-8;LC_MONETARY=C;LC_MESSAGES=de_DE.UTF-8;LC_PAPER=de_DE.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=de_DE.UTF-8;LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base Best, Matthias Kurt Hornik wrote: Matthias Kohl writes: Dear developers, We want to use "\S4method" to document new S4-methods for "[" and "[<-". We use this for other functions/methods and it works without any problem, but in case of "[" and "[<-" we didn't manage to bring this to work. The problem occurs in the development version of our package "distrSim" which can be found under http://r-forge.r-project.org/R/?group_id=87. The warning we obtain is Bad \usage lines found in documentation object 'Subsetting-methods': \S4method{[}{SeqDataFrames}(x, i, j, k, drop = FALSE) \S4method{[<-}{SeqDataFrames}(x, i, j, k, value) Of course, we tried several different possibilities but with no success. You should be able to do the same you would do for indicating S3 methods for subsetting. I.e., \S4method{[}{SeqDataFrames}(x, i, j, k) <- value If this does not work, it is a bug. I'll have a look. -k Does someone know a package which shows a use case for this situation? I looked in several packages but could not found any. Thanks for your help! Matthias -- Dr. Matthias Kohl www.stamats.de __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Dr. Matthias Kohl www.stamats.de __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] R CMD check in R 2.8.0 checks also .svn folder
Dear developers, we develop our packages via r-forge and svn. Under R version 2.8.0 Under development (unstable) (2008-06-02 r45826) I now observe the following warning for our package "distrEx" * checking for executable files ... WARNING Found the following executable file(s): src/.svn/text-base/distrEx.dll.svn-base Source packages should not contain undeclared executable files. See section 'Package structure' in manual 'Writing R Extensions'. Hence, R CMD check also checks the .svn-folder. I don't mind to get this warning. I just would like to know if this is intended and if this might have an influence on package building. (This warning doesn't occur under R version 2.7.0 Patched (2008-06-03 r45828)) My session info is: R version 2.8.0 Under development (unstable) (2008-06-02 r45826) i686-pc-linux-gnu locale: LC_CTYPE=de_DE.UTF-8;LC_NUMERIC=C;LC_TIME=de_DE.UTF-8;LC_COLLATE=de_DE.UTF-8;LC_MONETARY=C;LC_MESSAGES=de_DE.UTF-8;LC_PAPER=de_DE.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=de_DE.UTF-8;LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base Best regards, Matthias -- Dr. Matthias Kohl www.stamats.de __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] pairwise.wilcox.test for paired samples
Dear R Core, pairwise.wilcox.test does not handle "paired = TRUE" correctly; e.g. set.seed(13) x <- rnorm(20) g <- c(rep(1, 10), rep(2, 10)) wilcox.test(x ~ g)$p.value # 0.075 pairwise.wilcox.test(x, g)$p.value # 0.075, o.k wilcox.test(x ~ g, paired = TRUE)$p.value # 0.105 pairwise.wilcox.test(x, g, paired = TRUE)$p.value # 0.075, wrong The line wilcox.test(xi, xj, ...)$p.value should read wilcox.test(xi, xj, paired = paired, ...)$p.value Best regards, Matthias my sessionInfo: R version 2.8.0 Patched (2008-10-23 r46779) i686-pc-linux-gnu locale: LC_CTYPE=de_DE.UTF-8;LC_NUMERIC=C;LC_TIME=de_DE.UTF-8;LC_COLLATE=de_DE.UTF-8;LC_MONETARY=C;LC_MESSAGES=de_DE.UTF-8;LC_PAPER=de_DE.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=de_DE.UTF-8;LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base -- Dr. Matthias Kohl www.stamats.de __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] misc subdirectory
make "misc" a subfolder of "inst" hth Matthias On 24.08.2012 19:32, David L Lorenz wrote: The utils package has a misc folder, and some other packages have folders that are not listed in the R-extensions documentation (?data?, ? demo?, ?exec?, ?inst?, ?man?, ?po?, ?src?, and ?tests?). I'd like to be able to put some ancillary data into a misc folder, but it's mere presence in the source folder or source tarball (created with R CMD build) does not mean that it gets put into the zip file (I'm using Windoze) for the package. How do I get an extra, nonstandard subdirectory into a package? Thanks. Dave [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Prof. Dr. Matthias Kohl www.stamats.de __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel