[Rd] R CMD check may not detect a code/documentation mismatch
For the package at http://www.cs.cas.cz/~savicky/R-devel/something_0.0.0.tar.gz which is a minor part of some other package only to demonstrate the problem, i get (under R version 2.11.0 Under development 2009-12-12 r50714 and also under R-2.9.2, openSUSE 11.1 (x86_64) and CentOS release 5.2) R CMD check something_0.0.0.tar.gz ... * checking Rd files ... OK * checking Rd metadata ... OK * checking Rd cross-references ... OK * checking for missing documentation entries ... OK * checking for code/documentation mismatches ... OK * checking Rd \usage sections ... OK * checking examples ... NONE * checking PDF version of manual ... OK although the package code contains testCoreNA <- function() and the documentation contains \usage{ testCoreClass(verbose=0) testCoreAttrEval(verbose=0) testCoreReg(verbose=0) testCoreNA(verbose=0) } There is a mismatch between code and documentation of testCoreNA(). Is the problem caused by having four entries in \usage{} section? Petr Savicky. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] R CMD check may not detect a code/documentation mismatch
Petr Savicky wrote: For the package at http://www.cs.cas.cz/~savicky/R-devel/something_0.0.0.tar.gz which is a minor part of some other package only to demonstrate the problem, i get (under R version 2.11.0 Under development 2009-12-12 r50714 and also under R-2.9.2, openSUSE 11.1 (x86_64) and CentOS release 5.2) R CMD check something_0.0.0.tar.gz ... * checking Rd files ... OK * checking Rd metadata ... OK * checking Rd cross-references ... OK * checking for missing documentation entries ... OK * checking for code/documentation mismatches ... OK * checking Rd \usage sections ... OK * checking examples ... NONE * checking PDF version of manual ... OK although the package code contains testCoreNA <- function() and the documentation contains \usage{ testCoreClass(verbose=0) testCoreAttrEval(verbose=0) testCoreReg(verbose=0) testCoreNA(verbose=0) } There is a mismatch between code and documentation of testCoreNA(). Is the problem caused by having four entries in \usage{} section? Hmm, looks more like a thinko in this code inside codoc(): functions_in_code <- Filter(function(f) { f <- get(f, envir = code_env) is.function(f) && (length(formals(f)) > 0L) }, objects_in_code) which, further down the line, causes functions with no formal arguments to be skipped when compared to the usage section. Browse[2]> debug: ind <- (!functions %in% functions_to_be_ignored & functions %in% functions_in_code) Browse[2]> functions [1] "testCoreClass""testCoreAttrEval" "testCoreReg" "testCoreNA" Browse[2]> debug: bad_functions <- mapply(functions[ind], exprs[ind], FUN = function(x, y) check_codoc(x, as.pairlist(as.alist.call(y[-1L]))), SIMPLIFY = FALSE) Browse[2]> ind [1] TRUE TRUE TRUE FALSE I.e. testCoreNA is never tested by check_codoc. There may of course be a rationale for this, but it escapes me... -- O__ Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] O(N log N) Kendall Tau
I've noticed that the implementation of Kendall's Tau in R is O(N^2). The following reference describes how it can be done in O(N log N): A Computer Method for Calculating Kendall's Tau with Ungrouped Data William R. Knight Journal of the American Statistical Association, Vol. 61, No. 314, Part 1 (Jun., 1966), pp. 436-439 http://www.jstor.org/pss/2282833 I'm interested in contributing an implementation of this algorithm to R. However, I have a few questions: 1. Would it likely be accepted if well-implemented? 2. cov.c in the main/ directory of the R source tree seems to contain at least 4 different but nearly identical implementations of Kendall's Tau: cov_complete1, cov_complete2, cov_na1, and cov_na2. I can't tell why. The file is very difficult to read because of its lack of comments, (ab)use of macros and improper indentation. As I will probably need to modify this file, can some seasoned veteran please explain what the heck is going on in this file? __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] O(N log N) Kendall Tau
On 13 December 2009 at 00:38, David Simcha wrote: | I've noticed that the implementation of Kendall's Tau in R is O(N^2). | The following reference describes how it can be done in O(N log N): | | A Computer Method for Calculating Kendall's Tau with Ungrouped Data | William R. Knight | Journal of the American Statistical Association, Vol. 61, No. 314, Part | 1 (Jun., 1966), pp. 436-439 | http://www.jstor.org/pss/2282833 Interesting. I recently used the performance of cor(X, method="kendall") as a contrast to the 26-fold speedup when (!!) using gpuCor(X, method="kendall") from the nice gputools package by Josh Buckner and Mark Seligman. That was using the GPU in a QuadroFX 4800 with a 1206 x 477 matrix; the full example is in my most recent 'Intro to HPC with R' slides. | I'm interested in contributing an implementation of this algorithm to | R. However, I have a few questions: | | 1. Would it likely be accepted if well-implemented? | 2. cov.c in the main/ directory of the R source tree seems to contain | at least 4 different but nearly identical implementations of Kendall's | Tau: cov_complete1, cov_complete2, cov_na1, and cov_na2. I can't tell | why. Combine your bottom-up code analysis with a top-down usage analysis -- open up R and read 'help(cov)'. There are different ways to deal with missing observations. | The file is very difficult to read because of its lack of | comments, (ab)use of macros and improper indentation. As I will | probably need to modify this file, can some seasoned veteran please | explain what the heck is going on in this file? Again, I think reading the help file along with the code may prove beneficial. The R implementation is pretty consistent across files to you will have to get used to those C level macros if you want to modify code at that level. The R Extensions manual may prove helpful. Lastly, as a matter of style, I find people are more likely to help you if you don't hit them first with a two-by-four of 'your code and style is horrid'. Cheers, Dirk -- Three out of two people have difficulties with fractions. __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] O(N log N) Kendall Tau
David Simcha wrote: I've noticed that the implementation of Kendall's Tau in R is O(N^2). The following reference describes how it can be done in O(N log N): A Computer Method for Calculating Kendall's Tau with Ungrouped Data William R. Knight Journal of the American Statistical Association, Vol. 61, No. 314, Part 1 (Jun., 1966), pp. 436-439 http://www.jstor.org/pss/2282833 I'm interested in contributing an implementation of this algorithm to R. However, I have a few questions: 1. Would it likely be accepted if well-implemented? 2. cov.c in the main/ directory of the R source tree seems to contain at least 4 different but nearly identical implementations of Kendall's Tau: cov_complete1, cov_complete2, cov_na1, and cov_na2. I can't tell why. The file is very difficult to read because of its lack of comments, (ab)use of macros and improper indentation. As I will probably need to modify this file, can some seasoned veteran please explain what the heck is going on in this file? Well, it is not that hard to find that the functions you mentioned are all used (for different cases) in the main function do_cov that is called by R's cov() function. Given you provide a well tested implementation based on a published algorithm that is numerically as stable as the method already implemented in R, including all features, and gives identical results, I think it is very likely that your implementation will replace the one that is currently used in R. Best, Uwe Ligges __ 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] raster support in graphics devices
Hi baptiste auguie wrote: Hi, Thanks for the fix. I hope the quartz bugs are not related to a bad configuration on my side (I don't have access to another Mac to test it). I have not been able to get hold of a 10.5 (Leopard) Mac either. Keen to hear confirmation from anyone else with this problem. I was quite happy with this proof-of-concept of filling patterns for rectangles, and I was wondering if perhaps you had considered adding a similar tiling option to grid.raster (at the C level)? I have thought a bit about drawing the same image multiple times (more in the context of using a bitmap for a plotting symbol). I imagine something like being able to "add" a raster image to a device and then simply "refer" to that image (e.g., by name) is needed. Still thinking about the right way to go about that though. Paul Best regards, baptiste 2009/12/6 Paul Murrell : Hi baptiste auguie wrote: Hi again, I found two possible bugs related to grid.raster, one with the quartz device and the other with pdf. In my example I was playing with the idea of using grid.raster to create a filling pattern for rectangles. The pdf output does not seem to respect the clipping (it may have nothing to do with grid.raster though), whilst the quartz device with pdf file output often crashes for more than 4 different raster objects (but not always). I'm afraid I couldn't pinpoint the exact circumstance of the crash with a more concise example. Thanks again for the report. I have committed a fix for the PDF clipping. Still looking at the Quartz crashes. Paul Thanks in advance for any insights, baptiste ### Start example ### library(grid) ## create a motif grid45 <- function(..., width=0.5, height=0.5){ x11(width=width, height=height) grid.polygon(...) m <- grid.cap() dev.off() invisible(m) } .grid45 <- grid45() ## grid.raster(.grid45) tile.motif <- function(m, nx=10, ny=nx){ cols <- matrix(rep(m, nx), ncol=ncol(m)*nx, byrow=F) matrix(rep(t(cols), ny), nrow=nrow(cols)*ny, byrow=T) } ## quartz() ## grid.raster(tile.motif(.grid45, 2, 3)) patternGrob <- function(x=unit(0.5, "npc"), y=unit(0.5, "npc"), width=unit(1, "npc"), height=unit(1, "npc"), motif=matrix("white"), AR=1, motif.width=unit(5, "mm"), motif.height=AR*motif.width, pattern.offset=c(0, 0), # unimplemented default.units="npc", clip=TRUE, # testing purposes gp=gpar(fill=NA), ...) { grob(x=x, y=y, width=width, height=height, motif=motif, motif.width=motif.width, motif.height=motif.height, clip=clip, gp=gp, ..., cl="pattern") } widthDetails.pattern <- function(x) x$width heightDetails.pattern <- function(x) x$height drawDetails.pattern <- function(x, recording=TRUE){ ## calculate the number of tiles nx <- ceiling(convertUnit(x$width, "in", value=TRUE) / convertUnit(x$motif.width, "in", value=TRUE)) + 1 ny <- ceiling(convertUnit(x$height, "in", axisFrom = "y", value=TRUE) / convertUnit(x$motif.height, "in", axisFrom = "y", value=TRUE)) + 1 width <- convertUnit(x$width, "in") height <- convertUnit(x$height, "in", axisFrom = "y") ## clip the raster pushViewport(viewport(x=x$x, y=x$y, width=x$width, height=x$height, clip=x$clip)) grid.raster(tile.motif(x$motif, nx, ny), width=nx*x$motif.width, height=ny*x$motif.height) upViewport() ## overlay the rectangle grid.rect(x=x$x, y=x$y, width=x$width, height=x$height, just="center", gp=x$gp) } g <- patternGrob(x=0.7, width=unit(0.3, "npc"), height=unit(5.2, "cm"), clip=TRUE, motif=.grid45) ## interactive use: OK quartz() grid.newpage() grid.draw(g) ## png: OK png(file="pngClip.png") grid.newpage() grid.draw(g) dev.off() ## pdf: clipping does not occur pdf(file="pdfClip.pdf") grid.newpage() grid.draw(g) dev.off() ## quartz pdf: OK, but see below quartz(file="quartzClip.pdf", type="pdf") grid.newpage() grid.draw(g) dev.off() g1 <- patternGrob(x=0.2, width=unit(0.2, "npc"), height=unit(5.2, "cm"), clip=TRUE, motif=.grid45) g2 <- patternGrob(x=0.4, width=unit(0.2, "npc"), height=unit(5.2, "cm"), clip=TRUE, motif=.grid45) g3 <- patternGrob(x=0.6, width=unit(0.2, "npc"), height=unit(5.2, "cm"), clip=TRUE, motif=.grid45) g4 <- patternGrob(x=0.8, width=unit(0.2, "npc"), height=unit(5.2, "cm"), clip=TRUE, motif=.grid45) quartz(file="quartzClip2.pdf", type="pdf") grid.newpage() grid.draw(g1) grid.draw(g2) grid.draw(g3) grid.draw(g4) dev.off() *** caught segfault *** address 0x15dda018, cause 'memory not mapped' Traceback: 1: dev.off() sessionInfo() R version 2.11.0 Under development (unstable) (2009-11-30 r5062