From noreply at r-forge.r-project.org Tue Nov 4 10:57:27 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 4 Nov 2014 10:57:27 +0100 (CET) Subject: [Dplr-commits] r903 - pkg/dplR Message-ID: <20141104095727.DCFCA1877E0@r-forge.r-project.org> Author: mvkorpel Date: 2014-11-04 10:57:27 +0100 (Tue, 04 Nov 2014) New Revision: 903 Modified: pkg/dplR/ChangeLog pkg/dplR/DESCRIPTION Log: Fixed typos in ChangeLog Modified: pkg/dplR/ChangeLog =================================================================== --- pkg/dplR/ChangeLog 2014-10-28 09:19:21 UTC (rev 902) +++ pkg/dplR/ChangeLog 2014-11-04 09:57:27 UTC (rev 903) @@ -259,14 +259,14 @@ File: corr.series.seg.R -------------------- -- Added method argument to specify method for cor.test(). Defauts to +- Added method argument to specify method for cor.test(). Defaults to "spearman." File: corr.rwl.seg.R -------------------- - Removed yr.range() function in favor of yr.range() in helpers.R. They are identical for all practical purposes. -- Added method argument to specify method for cor.test(). Defauts to +- Added method argument to specify method for cor.test(). Defaults to "spearman." File: interseries.cor.R ------------------------- @@ -376,7 +376,7 @@ File: gini.c ------------ -- Simplified expression for gini coefficent reduces number of +- Simplified expression for gini coefficient reduces number of arithmetic operations performed - Fewer calls to other functions (use of the new cumulative sum function) @@ -636,7 +636,7 @@ ------------------- - Fixed trimming of all-NA rows -- Fixed a bug that could crash R if the fided-width columns of the input +- Fixed a bug that could crash R if the fixed-width columns of the input file did not follow the (loose) specifications of the Tucson format - AB: Note to dplR developers that this is a result of a poor standard in the Tucson format but this fix is needed to work with files that are @@ -1994,7 +1994,7 @@ 2011-05-18 Andy Bunn * CHANGES IN dplR VERSION 1.4.0 -* Incporporation of TRiDAS via Mikko Korpela, May 16, 2011 +* Incorporation of TRiDAS via Mikko Korpela, May 16, 2011 File: NAMESPACE --------------- @@ -2075,7 +2075,7 @@ 2010-11-15 Andy Bunn * CHANGES IN dplR VERSION 1.3.9 * Added an option to control the colors in plot.wavelet(). -* Added an option to plot wavelets side by side instead of stacked (plus a few owther beutifications). +* Added an option to plot wavelets side by side instead of stacked (plus a few other beautifications). * Changes mostly in wavelet.plot.R and arg side.by.side and key.col added to the help. * Added an axis on side three for the wavelet plot. @@ -2223,7 +2223,7 @@ * Modified wavelet.plot() to produce a better looking plot and put the wavelet code into a new function called morlet(). * Deprecated cwt.filled.contour * Added normalize1 to NAMESPACE -* Added arguiment label.cex to pass to axis to increase the size of the labels on the plot in corr.rwl.seg() and modified +* Added argument label.cex to pass to axis to increase the size of the labels on the plot in corr.rwl.seg() and modified the help file accordingly. This change was requested by a user and seems like a good idea. * Corrected some spelling in help for corr.rwl.seg(), ccf.series.seg(), and corr.series.seg(). I'm sure there is more. 2010-07-17 Andy Bunn @@ -2231,7 +2231,7 @@ * Modified rcs() to stop() if any of the pith offsets are <1 or not integers. The help file indicated that this should be so but it's now explicit in the code. * Fixed a bug in corr.rwl.seg() where floating series were not being drawn properly - the plot had them displaying all the way to the - max yr range b/c of an inexing problem. Also made some cosmetic changes to the guides in between segments for the graph. I do NOT + max yr range b/c of an indexing problem. Also made some cosmetic changes to the guides in between segments for the graph. I do NOT like the way the plot on this function is done with the odd bin and even bin looping. Very clunky and confusing to look at. The correlation part is fine and the graph is nice but the logic of the plot is silly. * Clarified language the help page for corr.rwl.seg(). @@ -2244,12 +2244,12 @@ ccf.df$bin factor to be the same order as bins[,1]. * Clarified language the help page for ccf.series.rwl(). * Improved series.rwl.plot() to give more diagnostic information in four plots. -* Improved the help page for series.rwl.plot() to beter explain what it now does. +* Improved the help page for series.rwl.plot() to better explain what it now does. 2010-07-05 Andy Bunn * CHANGES IN dplR VERSION 1.3.5 * Modified the help file for write.crn() so that the elev in the hdr will be written in a way that might - be more robust in terms of the ITRDB standard. But, it's very clunky and silly to depend on an unrelaible + be more robust in terms of the ITRDB standard. But, it's very clunky and silly to depend on an unreliable standard. I also added some text to the help file for write.tucson() to indicate that the header should be thought of as experimental. Thank goodness Mikko is working on getting tridas implemented. * Fixed a bug in rcs() where the rc was calculated wrong if none. The function implicitly assumed Modified: pkg/dplR/DESCRIPTION =================================================================== --- pkg/dplR/DESCRIPTION 2014-10-28 09:19:21 UTC (rev 902) +++ pkg/dplR/DESCRIPTION 2014-11-04 09:57:27 UTC (rev 903) @@ -3,7 +3,7 @@ Type: Package Title: Dendrochronology Program Library in R Version: 1.6.1 -Date: 2014-10-27 +Date: 2014-11-04 Authors at R: c(person("Andy", "Bunn", role = c("aut", "cph", "cre", "trl"), email = "andy.bunn at wwu.edu"), person("Mikko", "Korpela", role = c("aut", "trl")), person("Franco", "Biondi", From noreply at r-forge.r-project.org Tue Nov 4 11:14:05 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 4 Nov 2014 11:14:05 +0100 (CET) Subject: [Dplr-commits] r904 - pkg/dplR Message-ID: <20141104101405.185AF184EEC@r-forge.r-project.org> Author: mvkorpel Date: 2014-11-04 11:14:04 +0100 (Tue, 04 Nov 2014) New Revision: 904 Modified: pkg/dplR/ChangeLog Log: Tiny typo fixed Modified: pkg/dplR/ChangeLog =================================================================== --- pkg/dplR/ChangeLog 2014-11-04 09:57:27 UTC (rev 903) +++ pkg/dplR/ChangeLog 2014-11-04 10:14:04 UTC (rev 904) @@ -368,7 +368,7 @@ Files: exactsum.c, exactsum.h ----------------------------- -- Reuse of code between function by using the C preprocessor +- Reuse of code between functions by using the C preprocessor - New (internal to dplR C code) function cumsum (cumulative sum, overwrites input array) - size_t n From noreply at r-forge.r-project.org Wed Nov 5 15:47:53 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 5 Nov 2014 15:47:53 +0100 (CET) Subject: [Dplr-commits] r905 - pkg/dplR Message-ID: <20141105144753.7E12B18760B@r-forge.r-project.org> Author: mvkorpel Date: 2014-11-05 15:47:53 +0100 (Wed, 05 Nov 2014) New Revision: 905 Modified: pkg/dplR/.Rbuildignore Log: Ignore 'auto' directories used by AUCTeX (Emacs) Modified: pkg/dplR/.Rbuildignore =================================================================== --- pkg/dplR/.Rbuildignore 2014-11-04 10:14:04 UTC (rev 904) +++ pkg/dplR/.Rbuildignore 2014-11-05 14:47:53 UTC (rev 905) @@ -8,3 +8,4 @@ ^.*-tikzDictionary$ ^.*\.Rproj$ ^\.Rproj\.user$ +^.*/auto$ From noreply at r-forge.r-project.org Wed Nov 5 16:39:59 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 5 Nov 2014 16:39:59 +0100 (CET) Subject: [Dplr-commits] r906 - in pkg/dplR: inst/doc vignettes Message-ID: <20141105153959.2A0E7185979@r-forge.r-project.org> Author: mvkorpel Date: 2014-11-05 16:39:58 +0100 (Wed, 05 Nov 2014) New Revision: 906 Modified: pkg/dplR/inst/doc/ pkg/dplR/vignettes/ Log: Added 'auto' directory of AUCTeX (Emacs) to svn:ignore Property changes on: pkg/dplR/inst/doc ___________________________________________________________________ Modified: svn:ignore - svn*.tmp .* *~ cache figure *.Rout *-tikzDictionary *.aux *.bbl *.blg *.fdb_latexmk *.glo *.gls *.glg *.idx *.ind *.ilg *.lof *.log *.lot *.out *.synctex.gz *.tex *.toc + svn*.tmp .* *~ cache figure *.Rout *-tikzDictionary *.aux *.bbl *.blg *.fdb_latexmk *.glo *.gls *.glg *.idx *.ind *.ilg *.lof *.log *.lot *.out *.synctex.gz *.tex *.toc auto Property changes on: pkg/dplR/vignettes ___________________________________________________________________ Modified: svn:ignore - *.aux *.bbl *.blg *.fdb_latexmk *.glo *.gls *.glg *.idx *.ind *.ilg *.lof *.log *.lot *.out *.synctex.gz *.tex *.toc intro-dplR*.pdf svn*.tmp .* *~ + *.aux *.bbl *.blg *.fdb_latexmk *.glo *.gls *.glg *.idx *.ind *.ilg *.lof *.log *.lot *.out *.synctex.gz *.tex *.toc intro-dplR*.pdf svn*.tmp .* *~ auto From noreply at r-forge.r-project.org Wed Nov 5 16:47:20 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 5 Nov 2014 16:47:20 +0100 (CET) Subject: [Dplr-commits] r907 - in pkg/dplR: . R man Message-ID: <20141105154720.C8C3618753B@r-forge.r-project.org> Author: mvkorpel Date: 2014-11-05 16:47:20 +0100 (Wed, 05 Nov 2014) New Revision: 907 Modified: pkg/dplR/ChangeLog pkg/dplR/DESCRIPTION pkg/dplR/R/spag.plot.R pkg/dplR/man/spag.plot.Rd Log: Added 'useRaster' and 'res' arguments to spag.plot(), as previously used in wavelet.plot(). Modified: pkg/dplR/ChangeLog =================================================================== --- pkg/dplR/ChangeLog 2014-11-05 15:39:58 UTC (rev 906) +++ pkg/dplR/ChangeLog 2014-11-05 15:47:20 UTC (rev 907) @@ -124,6 +124,14 @@ plot with less than the full number of rows can fit in a smaller device and text on the sides won't be clipped. +File: spag.plot.R +----------------- + +- Added two options to spag.plot(). + 'useRaster': draw the tree-ring series as a raster image? (default + 'FALSE') + 'res': resolution of the tree-ring series when 'useRaster' is 'TRUE' + File: timeseries-dplR.Rnw ------------------------- Modified: pkg/dplR/DESCRIPTION =================================================================== --- pkg/dplR/DESCRIPTION 2014-11-05 15:39:58 UTC (rev 906) +++ pkg/dplR/DESCRIPTION 2014-11-05 15:47:20 UTC (rev 907) @@ -3,7 +3,7 @@ Type: Package Title: Dendrochronology Program Library in R Version: 1.6.1 -Date: 2014-11-04 +Date: 2014-11-05 Authors at R: c(person("Andy", "Bunn", role = c("aut", "cph", "cre", "trl"), email = "andy.bunn at wwu.edu"), person("Mikko", "Korpela", role = c("aut", "trl")), person("Franco", "Biondi", Modified: pkg/dplR/R/spag.plot.R =================================================================== --- pkg/dplR/R/spag.plot.R 2014-11-05 15:39:58 UTC (rev 906) +++ pkg/dplR/R/spag.plot.R 2014-11-05 15:47:20 UTC (rev 907) @@ -1,4 +1,5 @@ -spag.plot <- function(rwl, zfac=1, ...){ +spag.plot <- function(rwl, zfac=1, useRaster = FALSE, res = 150, ...){ + stopifnot(is.logical(useRaster), length(useRaster) == 1) nseries <- ncol(rwl) if (nseries == 0) { stop("empty 'rwl' given, nothing to draw") @@ -20,8 +21,23 @@ axes=FALSE, ylab="", xlab=gettext("Year", domain="R-dplR")) abline(h=1:nseries, col="grey") grid(ny = NA) - for (i in 1:nseries) { + if (is.na(useRaster)) { + useRaster2 <- names(dev.cur()) %in% c("pdf", "postscript") + } else { + useRaster2 <- useRaster + } + cl <- quote(for (i in 1:nseries) { lines(yr, rwl2[, i], ...) + }) + if (useRaster2) { + tryCatch(rasterPlot(cl, res = res), + error = function(e) { + message(as.character(e), appendLF = FALSE) + message("reverting to useRaster=FALSE") + eval(cl) + }) + } else { + eval(cl) } tmp.seq <- seq(from=1, to=nseries, by=2) axis(2, at=tmp.seq, Modified: pkg/dplR/man/spag.plot.Rd =================================================================== --- pkg/dplR/man/spag.plot.Rd 2014-11-05 15:39:58 UTC (rev 906) +++ pkg/dplR/man/spag.plot.Rd 2014-11-05 15:47:20 UTC (rev 907) @@ -5,13 +5,21 @@ Makes a spaghetti plot of tree-ring data. } \usage{ -spag.plot(rwl, zfac = 1, \dots) +spag.plot(rwl, zfac = 1, useRaster = FALSE, res = 150, \dots) } \arguments{ \item{rwl}{ a \code{data.frame} with series as columns and years as rows such as that produced by \code{\link{read.rwl}}. } \item{zfac}{ a multiplier for \code{\var{rwl}} to enhance clarity when plotting. } + \item{useRaster}{A \code{logical} flag. If \code{TRUE}, the tree-ring + series are drawn as a raster image. Other parts of the plot are + not affected. Other choices are \code{NA} (automatic) and + \code{FALSE} (use vector graphics, the default). See + \code{\link{wavelet.plot}}. } + \item{res}{A \code{numeric} vector of length 1. The resolution + (pixels per inch) of the tree-ring series when a raster image is + used. } \item{\dots}{ arguments to be passed to \code{\link{lines}}. } } \details{ From noreply at r-forge.r-project.org Thu Nov 6 16:22:55 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 6 Nov 2014 16:22:55 +0100 (CET) Subject: [Dplr-commits] r908 - in pkg/dplR: . inst/doc Message-ID: <20141106152256.0EC391877EE@r-forge.r-project.org> Author: mvkorpel Date: 2014-11-06 16:22:55 +0100 (Thu, 06 Nov 2014) New Revision: 908 Modified: pkg/dplR/DESCRIPTION pkg/dplR/inst/doc/00_INDEX Log: Directory index now also mentions automatically copied and generated files Modified: pkg/dplR/DESCRIPTION =================================================================== --- pkg/dplR/DESCRIPTION 2014-11-05 15:47:20 UTC (rev 907) +++ pkg/dplR/DESCRIPTION 2014-11-06 15:22:55 UTC (rev 908) @@ -3,7 +3,7 @@ Type: Package Title: Dendrochronology Program Library in R Version: 1.6.1 -Date: 2014-11-05 +Date: 2014-11-06 Authors at R: c(person("Andy", "Bunn", role = c("aut", "cph", "cre", "trl"), email = "andy.bunn at wwu.edu"), person("Mikko", "Korpela", role = c("aut", "trl")), person("Franco", "Biondi", Modified: pkg/dplR/inst/doc/00_INDEX =================================================================== --- pkg/dplR/inst/doc/00_INDEX 2014-11-05 15:47:20 UTC (rev 907) +++ pkg/dplR/inst/doc/00_INDEX 2014-11-06 15:22:55 UTC (rev 908) @@ -3,3 +3,8 @@ math-dplR.pdf Document: Mathematical Details of Functions in dplR math-dplR.R R code extracted from math-dplR.Rnw.txt math-dplR.Rnw.txt Literate programming source of math-dplR.pdf + +If this directory belongs to a packaged or installed dplR, there will +also be .pdf, .R and .Rnw versions of each proper (i.e. automatically +processed) vignette. At installation time, index.html appears. It is +an index to the proper vignettes. From noreply at r-forge.r-project.org Thu Nov 6 17:21:38 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 6 Nov 2014 17:21:38 +0100 (CET) Subject: [Dplr-commits] r909 - in pkg/dplR: . .R Message-ID: <20141106162138.D155F185F6D@r-forge.r-project.org> Author: mvkorpel Date: 2014-11-06 17:21:38 +0100 (Thu, 06 Nov 2014) New Revision: 909 Added: pkg/dplR/.R/ pkg/dplR/.R/Makevars pkg/dplR/.R/build.Renviron pkg/dplR/.R/check.Renviron pkg/dplR/00_README-developer Modified: pkg/dplR/.Rbuildignore Log: 00_README-developer: Instructions on how to * compress vignettes (reduces size of the package), * ensure the use of a UTF-8 locale when building and checking, and * enable extra compiler warnings when installing the package, to detect problems / non-standard practices in the C code. The instructions point to example settings files in .R/ Andy: Because you are the maintainer who builds the .tar.gz sent to CRAN, this is mostly for you! Added: pkg/dplR/.R/Makevars =================================================================== --- pkg/dplR/.R/Makevars (rev 0) +++ pkg/dplR/.R/Makevars 2014-11-06 16:21:38 UTC (rev 909) @@ -0,0 +1 @@ +CFLAGS=-Wall -pedantic -Wextra Added: pkg/dplR/.R/build.Renviron =================================================================== --- pkg/dplR/.R/build.Renviron (rev 0) +++ pkg/dplR/.R/build.Renviron 2014-11-06 16:21:38 UTC (rev 909) @@ -0,0 +1,2 @@ +LC_ALL=en_US.UTF-8 +_R_BUILD_COMPACT_VIGNETTES_=both Added: pkg/dplR/.R/check.Renviron =================================================================== --- pkg/dplR/.R/check.Renviron (rev 0) +++ pkg/dplR/.R/check.Renviron 2014-11-06 16:21:38 UTC (rev 909) @@ -0,0 +1 @@ +LC_ALL=en_US.UTF-8 Modified: pkg/dplR/.Rbuildignore =================================================================== --- pkg/dplR/.Rbuildignore 2014-11-06 15:22:55 UTC (rev 908) +++ pkg/dplR/.Rbuildignore 2014-11-06 16:21:38 UTC (rev 909) @@ -9,3 +9,4 @@ ^.*\.Rproj$ ^\.Rproj\.user$ ^.*/auto$ +^(|.*[^[:alpha:]])README-developer(|[^[:alpha:]].*)$ Added: pkg/dplR/00_README-developer =================================================================== --- pkg/dplR/00_README-developer (rev 0) +++ pkg/dplR/00_README-developer 2014-11-06 16:21:38 UTC (rev 909) @@ -0,0 +1,97 @@ +1. Introduction + +The (hidden) directory .R in the dplR source repository contains +suggested R initialization files to use when building, checking and +installing (compiling) the dplR package. The initialization files +should generally be placed in HOME/.R/ where HOME is the user's home +directory. Some customization may be required depending on the +platform. Check if the files already exist and combine the suggested +"dplR settings" with your previous settings if appropriate. + + +2. List of files included, and the settings explained + +* Makevars + +This file is used when R CMD INSTALL compiles the C source code +included in dplR. The compiler flags in the Makevars file should work +with the GCC compiler. Other compilers may require different flags. + +The following variables are set: + +CFLAGS=-Wall -pedantic -Wextra + + The purpose of the flags is to enable more thorough warnings than + those used by default [1, Customizing package compilation]. The + warnings are useful in the development phase when making changes to + the C code. Because all issues should be solved before releasing + the package on CRAN, there is no need to distribute a Makevars file + with dplR (as long as Makevars serves no other purpose than to add + more compile time checks). Spurious warnings may occur when using + an old compiler. A list of known cases: + - warning about imaginary constants being a GNU extension by + Apple's gcc 4.2, OS X 10.7 + +Note that a matching platform-specific Makevars file +(Makevars-R_PLATFORM, Makevars.win or Makevars.win64), if available, +takes precedence over a generic Makevars file. If you already have a +platform-specific Makevars file, consider adding these definitions +there. + +* build.Renviron + +This is used with R CMD build [2, Checking and building packages]. +The following environment variables are set: + +LC_ALL=en_US.UTF-8 + + The locale is set to use the UTF-8 character set and US English. + UTF-8 is used because dplR specifies UTF-8 as its Encoding in the + DESCRIPTION file. The language setting may not matter, but one must + be chosen, and the en_US.UTF-8 locale is probably available on most + systems. + +_R_BUILD_COMPACT_VIGNETTES_=both + + This enables the compression of vignettes and other PDFs, making the + dplR source package (.tar.gz) smaller. The value "both" means that + two compression steps (lossy and lossless) are performed. Two + programs must be available: Ghostscript [3] and QPDF [4]. Among + other things, the Ghostscript step applies lossy compression to + bitmap images using "ebook" quality (150 dpi) [5, 6]. This may + considerably reduce the size of the PDF. QPDF performs a lossless + compression. At the time of writing (dplR revision 908 on R-Forge, + Ghostscript 9.15, QPDF 5.12), the reduction in package size is 330 + KiB (18 %). [2, Building package tarballs; 7] + +* check.Renviron + +Settings for R CMD check [2, Checking and building packages]: locale +as in build.Renviron. + + +References + +[1] R Installation and Administration (R-devel). + http://cran.r-project.org/doc/manuals/r-devel/R-admin.html + (Accessed 2014-11-06) + +[2] Writing R Extensions (R-devel). + http://cran.r-project.org/doc/manuals/r-devel/R-exts.html + (Accessed 2014-11-06) + +[3] Ghostscript. http://ghostscript.com/ (Accessed 2014-11-06) + +[4] QPDF: A Content-Preserving PDF Transformation System. + http://qpdf.sourceforge.net/ (Accessed 2014-11-06) + +[5] File src/library/tools/R/build.R in the R source tree + +[6] compactPDF: Compact PDF Files. Rd help page accessible by running + "?tools::compactPDF" in the R command prompt. + +[7] Help text of "R CMD build" command line tool. Accessible by + running "R CMD build --help" in a command line interpreter. + +The version of R in 5, 6 and 7 was "R Under development (unstable) +(2014-11-03 r66928)". From noreply at r-forge.r-project.org Fri Nov 7 14:00:40 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 7 Nov 2014 14:00:40 +0100 (CET) Subject: [Dplr-commits] r910 - pkg/dplR/data Message-ID: <20141107130040.C7AA8187311@r-forge.r-project.org> Author: mvkorpel Date: 2014-11-07 14:00:40 +0100 (Fri, 07 Nov 2014) New Revision: 910 Modified: pkg/dplR/data/anos1.rda pkg/dplR/data/ca533.rda pkg/dplR/data/cana157.rda pkg/dplR/data/co021.rda pkg/dplR/data/gp.rwl.rda Log: Resaved data to save space. I built the package with --resave-data=best and replaced the .rda files that got smaller. The other data files increased in size by a few bytes. It's interesting that --resave-data would replace an original file with a (slightly) larger version. Why not just keep the original? Anyway, I kept the smaller "originals". Being slightly paranoid, I tested that the resaved data load() fine and are identical() to the previous versions. Modified: pkg/dplR/data/anos1.rda =================================================================== (Binary files differ) Modified: pkg/dplR/data/ca533.rda =================================================================== (Binary files differ) Modified: pkg/dplR/data/cana157.rda =================================================================== (Binary files differ) Modified: pkg/dplR/data/co021.rda =================================================================== (Binary files differ) Modified: pkg/dplR/data/gp.rwl.rda =================================================================== (Binary files differ) From noreply at r-forge.r-project.org Mon Nov 10 20:40:40 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 10 Nov 2014 20:40:40 +0100 (CET) Subject: [Dplr-commits] r911 - in pkg/dplR: . inst/doc vignettes Message-ID: <20141110194040.2DAB818045C@r-forge.r-project.org> Author: mvkorpel Date: 2014-11-10 20:40:39 +0100 (Mon, 10 Nov 2014) New Revision: 911 Modified: pkg/dplR/.Rbuildignore pkg/dplR/inst/doc/ pkg/dplR/vignettes/ Log: Some temporary files ignored Modified: pkg/dplR/.Rbuildignore =================================================================== --- pkg/dplR/.Rbuildignore 2014-11-07 13:00:40 UTC (rev 910) +++ pkg/dplR/.Rbuildignore 2014-11-10 19:40:39 UTC (rev 911) @@ -4,7 +4,7 @@ ^(.*/)?\..+$ ^inst/doc/cache(/.*)?$ ^inst/doc/figure(/.*)?$ -^inst/doc/.*\.Rout$ +^inst/doc/.*\.(Rnw|Rout|aux|bbl|blg|fdb_latexmk|fls|glo|gls|glg|idx|ind|ilg|lof|log|lot|out|synctex.gz|tex|toc)$ ^.*-tikzDictionary$ ^.*\.Rproj$ ^\.Rproj\.user$ Property changes on: pkg/dplR/inst/doc ___________________________________________________________________ Modified: svn:ignore - svn*.tmp .* *~ cache figure *.Rout *-tikzDictionary *.aux *.bbl *.blg *.fdb_latexmk *.glo *.gls *.glg *.idx *.ind *.ilg *.lof *.log *.lot *.out *.synctex.gz *.tex *.toc auto + svn*.tmp .* *~ cache figure *.Rout *-tikzDictionary *.aux *.bbl *.blg *.fdb_latexmk *.fls *.glo *.gls *.glg *.idx *.ind *.ilg *.lof *.log *.lot *.out *.synctex.gz *.tex *.toc auto Property changes on: pkg/dplR/vignettes ___________________________________________________________________ Modified: svn:ignore - *.aux *.bbl *.blg *.fdb_latexmk *.glo *.gls *.glg *.idx *.ind *.ilg *.lof *.log *.lot *.out *.synctex.gz *.tex *.toc intro-dplR*.pdf svn*.tmp .* *~ auto + *.aux *.bbl *.blg *.fdb_latexmk *.fls *.glo *.gls *.glg *.idx *.ind *.ilg *.lof *.log *.lot *.out *.synctex.gz *.tex *.toc intro-dplR*.pdf svn*.tmp .* *~ auto From noreply at r-forge.r-project.org Mon Nov 10 20:45:28 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 10 Nov 2014 20:45:28 +0100 (CET) Subject: [Dplr-commits] r912 - in pkg/dplR: . R man Message-ID: <20141110194528.509CD180FD8@r-forge.r-project.org> Author: mvkorpel Date: 2014-11-10 20:45:28 +0100 (Mon, 10 Nov 2014) New Revision: 912 Added: pkg/dplR/man/rasterPlot.Rd Modified: pkg/dplR/ChangeLog pkg/dplR/DESCRIPTION pkg/dplR/NAMESPACE pkg/dplR/R/rasterPlot.R Log: Exported and documented rasterPlot() Modified: pkg/dplR/ChangeLog =================================================================== --- pkg/dplR/ChangeLog 2014-11-10 19:40:39 UTC (rev 911) +++ pkg/dplR/ChangeLog 2014-11-10 19:45:28 UTC (rev 912) @@ -3,7 +3,7 @@ File: NAMESPACE --------------- -- Added latexify() and latexDate() to export list +- Added rasterPlot, latexify() and latexDate() to export list - Import readPNG from png. - Import more functions from grid. @@ -95,9 +95,8 @@ New file rasterPlot.R --------------------- -- New function rasterPlot(), internal to the package. Adds a - raster image drawn with low level graphics commands to the current - high level plot. +- New function rasterPlot(). Adds a raster image drawn with low + level graphics commands to the current high level plot. Files: rcompact.c, readloop.c ----------------------------- Modified: pkg/dplR/DESCRIPTION =================================================================== --- pkg/dplR/DESCRIPTION 2014-11-10 19:40:39 UTC (rev 911) +++ pkg/dplR/DESCRIPTION 2014-11-10 19:45:28 UTC (rev 912) @@ -3,7 +3,7 @@ Type: Package Title: Dendrochronology Program Library in R Version: 1.6.1 -Date: 2014-11-06 +Date: 2014-11-10 Authors at R: c(person("Andy", "Bunn", role = c("aut", "cph", "cre", "trl"), email = "andy.bunn at wwu.edu"), person("Mikko", "Korpela", role = c("aut", "trl")), person("Franco", "Biondi", Modified: pkg/dplR/NAMESPACE =================================================================== --- pkg/dplR/NAMESPACE 2014-11-10 19:40:39 UTC (rev 911) +++ pkg/dplR/NAMESPACE 2014-11-10 19:45:28 UTC (rev 912) @@ -42,7 +42,7 @@ write.compact, write.crn, write.rwl, write.tridas, write.tucson, plot.rwl, interseries.cor, summary.rwl, plot.crn, insert.ring, delete.ring, xskel.ccf.plot, xskel.plot, - latexify, latexDate) + latexify, latexDate, rasterPlot) S3method(print, redfit) S3method(plot, rwl) Modified: pkg/dplR/R/rasterPlot.R =================================================================== --- pkg/dplR/R/rasterPlot.R 2014-11-10 19:40:39 UTC (rev 911) +++ pkg/dplR/R/rasterPlot.R 2014-11-10 19:45:28 UTC (rev 912) @@ -1,29 +1,5 @@ -### Add raster elements to the active high-level plot. The given -### plotting commands are drawn using a temporary png() device. The -### raster image is read into memory and added to the original plot. -### -### Written by Mikko Korpela -### -### Arguments: -### x Low-level plotting commands representing elements to be added -### to the current plot. Examples: lines(), points(), text(), -### mtext(), .filled.contour() -### res Resolution in points per inch. -### Estimated useful range: 100 - 300. -### region Draw in the plot region or the figure region? -### The figure region contains the plot region and margins. -### Plotting in the outer margin is not supported. -### antialias Antialiasing option for png(). See argument 'antialias' -### in ?png. "none" is preferred for images in which color -### signifies value of data. The default (missing argument) -### is probably good for line plots. -### interpolate -### Argument passed to rasterImage(). A logical flag. -### The default is TRUE: use linear interpolation. -### Analogously to 'antialias', FALSE is preferred when -### color maps to value. -rasterPlot <- function(x, res = 150, region=c("plot", "figure"), antialias, - interpolate = TRUE) { +rasterPlot <- function(expr, res = 150, region=c("plot", "figure"), antialias, + bg = "transparent", interpolate = TRUE, ...) { if (identical(dev.capabilities("rasterImage")[["rasterImage"]], "no")) { stop("device does not support raster images") } @@ -50,10 +26,10 @@ fname <- tempfile(fileext = ".png") if (missing(antialias)) { png(fname, width = pngWidthHeight[1], height = pngWidthHeight[2], - units = "in", res = res, bg = "transparent") + units = "in", res = res, bg = bg, ...) } else { png(fname, width = pngWidthHeight[1], height = pngWidthHeight[2], - units = "in", res = res, bg = "transparent", antialias = antialias) + units = "in", res = res, bg = bg, antialias = antialias, ...) } ## Record things to do on exit (will be removed from list one-by-one) on.exit(dev.off()) @@ -70,10 +46,10 @@ ## Copy graphical parameters from original device to png: ## (margins), coordinates of plot region, etc. par(op) - ## Evaluate the plotting commands 'x' in the environment of the + ## Evaluate the plotting commands 'expr' in the environment of the ## caller of rasterPlot() pf <- parent.frame() - eval(x, pf) + eval(expr, pf) on.exit(dev.set(curDev)) on.exit(unlink(fname), add=TRUE) ## Close the png device @@ -119,4 +95,5 @@ xright = figRight, ytop = figTop, interpolate = interpolate) } + invisible(NULL) } Added: pkg/dplR/man/rasterPlot.Rd =================================================================== --- pkg/dplR/man/rasterPlot.Rd (rev 0) +++ pkg/dplR/man/rasterPlot.Rd 2014-11-10 19:45:28 UTC (rev 912) @@ -0,0 +1,94 @@ +\name{rasterPlot} +\alias{rasterPlot} +\title{ + Add Raster Elements to Plot +} +\description{ + This function takes plotting commands and uses a temporary + \code{\link{png}} bitmap graphics device to capture their output. The + resulting raster image is drawn in the plot or figure region of the + active high-level plot. +} +\usage{ +rasterPlot(expr, res = 150, region = c("plot", "figure"), antialias, + bg = "transparent", interpolate = TRUE, \dots) +} +\arguments{ + \item{expr}{ + Low-level plotting commands (\code{lines}, \code{points}, + \code{text}, \ldots) representing elements to be added to the + current plot. A \code{\link{call}} or an \code{\link{expression}}. + } + \item{res}{ + Resolution in points per inch (ppi). A numeric value. Suggested + values for different types of display media are given in + \code{\link{compactPDF}}. For example, the default 150 ppi + corresponds to \dQuote{ebook} quality. + } + \item{region}{ + The function can draw in the \code{"plot"} region or the + \code{"figure"} region which also includes \code{"mar"} margins (see + \code{\link{par}}). If the drawing commands in \code{\var{expr}} + contain no material for the margins, the default \code{"plot"} is + optimal. Plotting in the outer margins (\code{"oma"} in + \code{\link{par}}) is not supported. + } + \item{antialias}{ + Antialiasing argument passed to \code{\link{png}}. The default + (missing argument) is probably good for line plots but + \code{"none"} is preferred for images in which color signifies value + of data. + } + \item{bg}{ + Background color of the raster plot, an argument passed to + \code{\link{png}}. If the default \code{"transparent"} does not + work, try \code{"white"} or another color. Note that a + non-transparent background will mask any previous content in the + figure or plot region, depending on the value of \code{\var{region}}. + } + \item{interpolate}{ + Argument passed to \code{\link{rasterImage}}. A \code{logical} + flag. The default is \code{TRUE}: use linear interpolation. + Analogously to \code{\var{antialias}}, \code{FALSE} is preferred + when color maps to value. + } + \item{\dots}{ + Other arguments to \code{\link{png}}. + } +} +\details{ + The appropriate graphical parameters of the current graphics device + are copied to the temporary \code{\link{png}} device. Therefore the + appearance of the raster contents should be almost the same as when + directly drawn. + + The call or expression \code{\var{expr}} is evaluated in the + environment of the caller. + + Resizing a graphics device after a call to this function may distort + the image. For example, circle symbols will become ellipses if the + width to height ratio is not maintained (see \sQuote{Examples}). This + is in contrast to a standard plot in a display graphics device, + e.g. \code{\link{x11}}, where text and symbols maintain their size + when the device is resized. +} +\value{ + No return value. Used for the side effects. +} +\author{ + Mikko Korpela +} +\note{ + The graphics device used for the output must have support for + including raster images. See \code{"rasterImage"} in + \code{\link{dev.capabilities}}. + + The \R build must have a functional \code{\link{png}} device, which + requires one of the following \code{\link{capabilities}}: + \code{"png"}, \code{"aqua"} or \code{"cairo"}. +} +\examples{plot(1:5, type = "n") +foo <- runif(5, min = 1, max = 5) +rasterPlot(quote(points(foo))) +} +\keyword{ aplot } Property changes on: pkg/dplR/man/rasterPlot.Rd ___________________________________________________________________ Added: svn:eol-style + native From noreply at r-forge.r-project.org Mon Nov 10 22:16:26 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 10 Nov 2014 22:16:26 +0100 (CET) Subject: [Dplr-commits] r913 - pkg/dplR/inst/doc Message-ID: <20141110211626.83D4F186D67@r-forge.r-project.org> Author: mvkorpel Date: 2014-11-10 22:16:26 +0100 (Mon, 10 Nov 2014) New Revision: 913 Modified: pkg/dplR/inst/doc/math-dplR.R pkg/dplR/inst/doc/math-dplR.Rnw.txt pkg/dplR/inst/doc/math-dplR.bib pkg/dplR/inst/doc/math-dplR.pdf Log: Changes in the "pseudo-vignette" math-dplR: * Moved \documentclass to the beginning of the file. In the previous form, the document stopped compiling somewhere between knitr 1.5 and 1.6, the current version being 1.7. * Updated reference to the csaps function of Matlab. Noted that only the most recent Matlab version is openly documented on the Mathworks web site. * The R code in math-dplR did not change, but there are whitespace changes in math-dplR.R due to some changes in knitr. Modified: pkg/dplR/inst/doc/math-dplR.R =================================================================== --- pkg/dplR/inst/doc/math-dplR.R 2014-11-10 19:45:28 UTC (rev 912) +++ pkg/dplR/inst/doc/math-dplR.R 2014-11-10 21:16:26 UTC (rev 913) @@ -2,11 +2,9 @@ ## ----"try-matlab", echo=FALSE, results="hide"---------------------------- TRY_MATLAB <- TRUE - ## ----"flip-to-retry", echo=FALSE, results="hide", cache=TRUE------------- "tails" - ## ----"packages", echo=FALSE, results="hide"------------------------------ library(dplR) # latexify(), latexDate() latexify2 <- function(x) latexify(x, doublebackslash = FALSE) @@ -305,7 +303,6 @@ "\\texttt{ffcsaps}. The orange crosses show the results", "when~\\eqref{eq:pinv.book} is used instead.") - ## ----"response", opts.label="myfigures", fig.width=PAGE_WIDTH, fig.height=PAGE_HEIGHT-0.95, fig.cap=FFCSAPS_CAPTION, dependson=c("response-init", "response-comp"), cache.vars=character(0)---- op <- par(mfcol = c(3, 1), mgp = c(2, 0.75, 0), mar = par("mar") - 1) @@ -365,7 +362,6 @@ smoothed.R[, i] <- ffcsaps2(y, p = P[i]) } - ## ----"smoothed-matlab", dependson=c("smoothed-R", "flip-to-retry"), cache.vars=c("matlabValue", "matlabVersion", "smoothed.matlab")---- if (isTRUE(TRY_MATLAB)) { fnames <- tempfile(pattern=c("a", "b", "c"), fileext=".txt") @@ -412,7 +408,6 @@ matlabVersion <- "8.3.0.532 (R2014a)" # tested ok on 2014-05-12 } - ## ----"R-matlab-compare", cache=FALSE, error=FALSE------------------------ if (isTRUE(TRY_MATLAB) && matlabValue == 0) { stopifnot(identical(as.numeric(dim(smoothed.R)), c(100, 101)), @@ -436,7 +431,6 @@ paste("Spline with different values of smoothing parameter", "\\texttt{p} fitted to a noisy sine wave") - ## ----"smoothed", opts.label="myfigures", fig.width=PAGE_WIDTH, fig.height=PAGE_WIDTH, fig.cap=SMOOTHED_CAPTION, dependson="smoothed-R", cache.vars=character(0)---- ## Plot the input series and a few output series COLORS <- c("black", colorschemes$Categorical.12[c(10, 2, 6, 8)]) Modified: pkg/dplR/inst/doc/math-dplR.Rnw.txt =================================================================== --- pkg/dplR/inst/doc/math-dplR.Rnw.txt 2014-11-10 19:45:28 UTC (rev 912) +++ pkg/dplR/inst/doc/math-dplR.Rnw.txt 2014-11-10 21:16:26 UTC (rev 913) @@ -48,6 +48,8 @@ % required. A TeX Live installation, for example, should have all of % the required packages. +\documentclass[a4paper]{article} + <<"try-matlab", echo=FALSE, results="hide">>= TRY_MATLAB <- TRUE @ @@ -62,8 +64,6 @@ library(stats) @ -\documentclass[a4paper]{article} - \usepackage[T1]{fontenc} \usepackage[utf8]{inputenx} \usepackage[english]{babel} @@ -695,7 +695,13 @@ \texttt{p} as an argument and omit \texttt{nyrs} and \texttt{f}. I created a segment of a noisy sine wave and smoothed it with both functions using all values of \texttt{p} in the set \(\{0, 0.01, 0.02, -\dots, 1\}\), covering the whole range of useful values~\cite{csaps}. +\dots, 1\}\), covering the whole range of useful +values~\cite{csaps}\footnote{The Mathworks web site openly provides access + to the documentation of the latest Matlab version. Older documents + are available after a login to the website or by running \texttt{doc + csaps} in the command prompt of a particular Matlab version. The + author has checked that the documentation of \texttt{csaps} agrees + between versions 2012b, 2013a, 2013b, 2014a and 2014b.}. Using the R function \texttt{all.equal} to compare each pair of smoothed series, I found that the results of \texttt{csaps} and \texttt{ffcsaps} always matched. \Sexpr{matlabNoteText} Modified: pkg/dplR/inst/doc/math-dplR.bib =================================================================== --- pkg/dplR/inst/doc/math-dplR.bib 2014-11-10 19:45:28 UTC (rev 912) +++ pkg/dplR/inst/doc/math-dplR.bib 2014-11-10 21:16:26 UTC (rev 913) @@ -71,7 +71,7 @@ howpublished = {\url{http://www.mathworks.com/help/curvefit/csaps.html}}, OPTmonth = {}, OPTyear = {}, - note = {Accessed: 2014-05-12}, + note = {Accessed: 2014-11-10. Documentation of the latest version at that time (Matlab R2014b).}, OPTannote = {} } Modified: pkg/dplR/inst/doc/math-dplR.pdf =================================================================== (Binary files differ) From noreply at r-forge.r-project.org Tue Nov 11 10:14:55 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 11 Nov 2014 10:14:55 +0100 (CET) Subject: [Dplr-commits] r914 - in pkg/dplR: . man Message-ID: <20141111091455.E4F0B185156@r-forge.r-project.org> Author: mvkorpel Date: 2014-11-11 10:14:55 +0100 (Tue, 11 Nov 2014) New Revision: 914 Modified: pkg/dplR/DESCRIPTION pkg/dplR/man/rasterPlot.Rd Log: Added keyword "utilities" to rasterPlot.Rd Modified: pkg/dplR/DESCRIPTION =================================================================== --- pkg/dplR/DESCRIPTION 2014-11-10 21:16:26 UTC (rev 913) +++ pkg/dplR/DESCRIPTION 2014-11-11 09:14:55 UTC (rev 914) @@ -3,7 +3,7 @@ Type: Package Title: Dendrochronology Program Library in R Version: 1.6.1 -Date: 2014-11-10 +Date: 2014-11-11 Authors at R: c(person("Andy", "Bunn", role = c("aut", "cph", "cre", "trl"), email = "andy.bunn at wwu.edu"), person("Mikko", "Korpela", role = c("aut", "trl")), person("Franco", "Biondi", Modified: pkg/dplR/man/rasterPlot.Rd =================================================================== --- pkg/dplR/man/rasterPlot.Rd 2014-11-10 21:16:26 UTC (rev 913) +++ pkg/dplR/man/rasterPlot.Rd 2014-11-11 09:14:55 UTC (rev 914) @@ -92,3 +92,4 @@ rasterPlot(quote(points(foo))) } \keyword{ aplot } +\keyword{ utilities } From noreply at r-forge.r-project.org Mon Nov 17 22:01:13 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 17 Nov 2014 22:01:13 +0100 (CET) Subject: [Dplr-commits] r915 - in pkg/dplR: . R inst/unitTests man Message-ID: <20141117210113.2F0D5187731@r-forge.r-project.org> Author: mvkorpel Date: 2014-11-17 22:01:12 +0100 (Mon, 17 Nov 2014) New Revision: 915 Added: pkg/dplR/inst/unitTests/runit.utils.R Modified: pkg/dplR/ChangeLog pkg/dplR/DESCRIPTION pkg/dplR/NAMESPACE pkg/dplR/R/latexify.R pkg/dplR/inst/unitTests/runit.dplR.R pkg/dplR/man/latexify.Rd Log: Tweaks to latexify(): * Now enforces NFC normalization (using package "stringi") * Removes more whitespace when control characters are present * In .Rd: new reference, formatting, technical details Unit tests: * Test of uuid.gen() was moved to a new file, runit.utils.R * In the same file, there are new tests for latexify() and latexDate() Modified: pkg/dplR/ChangeLog =================================================================== --- pkg/dplR/ChangeLog 2014-11-11 09:14:55 UTC (rev 914) +++ pkg/dplR/ChangeLog 2014-11-17 21:01:12 UTC (rev 915) @@ -6,6 +6,7 @@ - Added rasterPlot, latexify() and latexDate() to export list - Import readPNG from png. - Import more functions from grid. +- Import stri_trans_nfc from stringi. File: DESCRIPTION ----------------- @@ -16,7 +17,7 @@ math-dplR.pdf easier with openPDF(). RColorBrewer provides an alternative palette to an example in wavelet.plot.Rd. -- New Imported package: png. +- New Imported packages: png and stringi. File: chron.R ------------- Modified: pkg/dplR/DESCRIPTION =================================================================== --- pkg/dplR/DESCRIPTION 2014-11-11 09:14:55 UTC (rev 914) +++ pkg/dplR/DESCRIPTION 2014-11-17 21:01:12 UTC (rev 915) @@ -3,7 +3,7 @@ Type: Package Title: Dendrochronology Program Library in R Version: 1.6.1 -Date: 2014-11-11 +Date: 2014-11-17 Authors at R: c(person("Andy", "Bunn", role = c("aut", "cph", "cre", "trl"), email = "andy.bunn at wwu.edu"), person("Mikko", "Korpela", role = c("aut", "trl")), person("Franco", "Biondi", @@ -20,7 +20,7 @@ Depends: R (>= 2.15.0) Imports: gmp (>= 0.5-2), graphics, grDevices, grid, stats, utils, digest (>= 0.2.3), lattice (>= 0.13-6), png (>= 0.1-1), - stringr (>= 0.4), XML (>= 2.1-0) + stringi, stringr (>= 0.4), XML (>= 2.1-0) Suggests: Biobase, dichromat (>= 1.2-3), foreach, forecast, iterators, knitr, RColorBrewer, RUnit (>= 0.4.25), tikzDevice, waveslim Description: This package contains functions for performing tree-ring Modified: pkg/dplR/NAMESPACE =================================================================== --- pkg/dplR/NAMESPACE 2014-11-11 09:14:55 UTC (rev 914) +++ pkg/dplR/NAMESPACE 2014-11-17 21:01:12 UTC (rev 915) @@ -22,6 +22,8 @@ importFrom(png, readPNG) +importFrom(stringi, stri_trans_nfc) + importFrom(stringr, str_pad, str_trim) importFrom(utils, head, installed.packages, read.fwf, tail, Modified: pkg/dplR/R/latexify.R =================================================================== --- pkg/dplR/R/latexify.R 2014-11-11 09:14:55 UTC (rev 914) +++ pkg/dplR/R/latexify.R 2014-11-17 21:01:12 UTC (rev 915) @@ -37,12 +37,12 @@ cat(y[encBytes], sep = "\n") y[encBytes] <- foo } + ## Remove control characters (not spaces!) + y <- gsub("(?![[:space:]])[[:cntrl:]]", "", y, perl=TRUE) ## Convert any sequence of whitespace to a single space. This ## substitution must be done before control characters because ## newline belongs to both groups. y <- gsub("[[:space:]]+", " ", y) - ## Remove control characters - y <- gsub("[[:cntrl:]]", "", y) ## Escape LaTeX special characters. ## Source: Scott Pakin (2009) The Comprehensive LaTeX Symbol List. ## Accessible through "texdoc symbols". @@ -72,16 +72,6 @@ if (isTRUE(doublebackslash)) { y <- gsub("\\", "\\\\", y, fixed=TRUE) } - ## gsub() may have changed encodings. Therefore we check them - ## again. - encs <- Encoding(y) - encLatin <- which(encs == "latin1") - if (length(encLatin) > 0) { - y[encLatin] <- iconv(y[encLatin], from = "latin1", to = "UTF-8") - } - encUnknown <- which(encs == "unknown") - if (length(encUnknown) > 0) { - y[encUnknown] <- iconv(y[encUnknown], to = "UTF-8") - } - y + ## Convert result to UTF-8 NFC encoding + stri_trans_nfc(y) } Modified: pkg/dplR/inst/unitTests/runit.dplR.R =================================================================== --- pkg/dplR/inst/unitTests/runit.dplR.R 2014-11-11 09:14:55 UTC (rev 914) +++ pkg/dplR/inst/unitTests/runit.dplR.R 2014-11-17 21:01:12 UTC (rev 915) @@ -728,33 +728,3 @@ checkTrue(is.nan(tbrm(seq.even, C=0)), msg="Robust mean of an even length sequence of consecutive integers is NaN when using a small C") } - -test.uuid.gen <- function() { - ## Setup - SAMP.SIZE <- 100 - ugen <- uuid.gen() - uuids <- character(SAMP.SIZE) - for(i in seq_len(SAMP.SIZE)) - uuids[i] <- ugen() - uuids.split <- strsplit(uuids, split="-", fixed=TRUE) - unique.nchar <- unique(t(sapply(uuids.split, nchar))) - unique.chars <- - unique(strsplit(paste(sapply(uuids.split, paste, collapse=""), - collapse=""), split=character(0))[[1]]) - all.4 <- unique(substr(uuids, 15, 15)) - one.of.four <- unique(substr(uuids, 20, 20)) - ## Test - checkEquals(SAMP.SIZE, length(unique(uuids)), msg="Unique IDs are unique") - checkTrue(all(nchar(uuids) == 36), msg="IDs have correct length") - checkTrue(all(sapply(uuids.split, length) == 5), - msg="IDs have 5 parts separated by dashes") - checkTrue(nrow(unique.nchar) == 1 && - all(as.vector(unique.nchar) == c(8, 4, 4, 4, 12)), - msg="The parts have lengths 8, 4, 4, 4, and 12") - checkTrue(all(unique.chars %in% c(as.character(0:9), letters[seq_len(6)])), - msg="In addition to dashes, IDs only contain hexadecimal digits") - checkEquals("4", all.4, - msg="IDs have a constant character \"4\" in one position") - checkTrue(all(one.of.four %in% c("8", "9", "a", "b")), - msg="IDs have a restricted character (4/16 choices) in one position") -} Added: pkg/dplR/inst/unitTests/runit.utils.R =================================================================== --- pkg/dplR/inst/unitTests/runit.utils.R (rev 0) +++ pkg/dplR/inst/unitTests/runit.utils.R 2014-11-17 21:01:12 UTC (rev 915) @@ -0,0 +1,226 @@ +test.uuid.gen <- function() { + ## Setup + SAMP.SIZE <- 100 + ugen <- uuid.gen() + uuids <- character(SAMP.SIZE) + for(i in seq_len(SAMP.SIZE)) + uuids[i] <- ugen() + uuids.split <- strsplit(uuids, split="-", fixed=TRUE) + unique.nchar <- unique(t(sapply(uuids.split, nchar))) + unique.chars <- + unique(strsplit(paste(sapply(uuids.split, paste, collapse=""), + collapse=""), split=character(0))[[1]]) + all.4 <- unique(substr(uuids, 15, 15)) + one.of.four <- unique(substr(uuids, 20, 20)) + ## Test + checkEquals(SAMP.SIZE, length(unique(uuids)), msg="Unique IDs are unique") + checkTrue(all(nchar(uuids) == 36), msg="IDs have correct length") + checkTrue(all(sapply(uuids.split, length) == 5), + msg="IDs have 5 parts separated by dashes") + checkTrue(nrow(unique.nchar) == 1 && + all(as.vector(unique.nchar) == c(8, 4, 4, 4, 12)), + msg="The parts have lengths 8, 4, 4, 4, and 12") + checkTrue(all(unique.chars %in% c(as.character(0:9), letters[seq_len(6)])), + msg="In addition to dashes, IDs only contain hexadecimal digits") + checkEquals("4", all.4, + msg="IDs have a constant character \"4\" in one position") + checkTrue(all(one.of.four %in% c("8", "9", "a", "b")), + msg="IDs have a restricted character (4/16 choices) in one position") +} + +test.latexify <- function() { + ## Number of test strings + ## (including one "extra difficult" case and one empty string) + SAMP.SIZE <- 50 + stopifnot(SAMP.SIZE >= 2) + MIN.LENGTH <- 1 + MAX.LENGTH <- 1000 + ## All ASCII characters except NUL (0) + characters <- rawToChar(as.raw(1:127), multiple = TRUE) + ## LaTeX special characters must be converted to commands + specialChars <- + c("{", "}", "\\", "#", "$", "%", "^", "&", "_", "~", "\"", "/") + specialStr <- paste(specialChars, collapse="") + ## latexify() is designed to convert any sequence of space + ## characters to a single regular space + spaceChars <- c("\t", "\n", "\v", "\f", "\r", " ") + spaceStr <- paste(spaceChars, collapse="") + ## latexify() is designed to drop control characters excluding spaces + controlChars <- setdiff(rawToChar(as.raw(c(1:31, 127)), multiple = TRUE), + spaceChars) + controlStr <- paste(controlChars, collapse="") + ## Decide the length of each test string + stringLengths <- sample(MIN.LENGTH:MAX.LENGTH, SAMP.SIZE - 2) + nTotal <- sum(stringLengths) + ## Create the test strings: + ## * The last element is a "difficult case". + ## * The other elements consist of a random sample of characters. + strStop <- cumsum(stringLengths) + strStart <- strStop - (stringLengths - 1) + testStrings <- + c(substring(paste(sample(rep(characters, length.out = nTotal)), + collapse=""), strStart, strStop), + paste(c(specialChars, + rev(specialChars), + rep(specialChars, each=3), + paste(specialChars, " \t")), + collapse=""), + "") + + ## Run latexify() on testStrings + ltxDouble <- latexify(testStrings, doublebackslash=TRUE) + ltxSingle <- latexify(testStrings, doublebackslash=FALSE) + + ## Tests + checkEquals(ltxDouble, + gsub("\\", "\\\\", ltxSingle, fixed=TRUE, useBytes=TRUE), + msg="doublebackslash argument works as expected") + checkTrue(!any(grepl(sprintf("[%s]", controlStr), + ltxSingle, useBytes=TRUE)), + msg="No control characters") + checkTrue(!any(grepl(sprintf("[%s]{2,}", spaceStr), + ltxSingle, useBytes=TRUE)), + msg="Sequence of space characters collapses into one space") + checkTrue(!any(grepl("\\\\", ltxSingle, fixed=TRUE)), + msg="No line breaks (double backslash)") + Letters <- paste(c(LETTERS, letters), collapse="") + textCommand <- sprintf("\\\\[%s]+", Letters) + commandAndGroup <- paste(textCommand, "\\{\\}", sep="") + commandsAt <- gregexpr(commandAndGroup, ltxSingle) + checkEquals(lapply(gregexpr(textCommand, ltxSingle), as.vector), + lapply(commandsAt, as.vector), + msg="Command name is terminated with empty group") + escape <- sprintf("\\\\[^%s](\\{\\})?", Letters) + escapesAt <- gregexpr(escape, ltxSingle) + + ## specialMap: record of special character -> command mapping + specialMap <- vector(mode="list", length = SAMP.SIZE) + ## Test that each test string was converted properly and prepare + ## specialMap + multiSpaceClass <- sprintf("[%s]+", spaceStr) + controlClass <- sprintf("[%s]", controlStr) + specialClass <- sprintf("[%s]", specialStr) + for (i in seq_len(SAMP.SIZE)) { + nChars <- nchar(ltxSingle[i]) + ## ltxChars: split ltxSingle[i] into strings representing one + ## character each + if (nChars > 0) { + coms <- commandsAt[[i]] + escs <- escapesAt[[i]] + comLengths <- attr(coms, "match.length") + escLengths <- attr(escs, "match.length") + if (length(coms) == 1 && coms == -1) { + coms <- numeric(0) + comLengths <- numeric(0) + } + if (length(escs) == 1 && escs == -1) { + escs <- numeric(0) + escLengths <- numeric(0) + } + comsAndEscs <- c(coms, escs) + idx <- order(comsAndEscs) + comEsc <- comsAndEscs[idx] + comEscLen <- c(comLengths, escLengths)[idx] + nComEsc <- length(comEsc) + charIdx <- numeric(nChars) + prv <- 0 + prvIdx <- 0 + for (j in seq_along(comEsc)) { + thisStart <- comEsc[j] + nSingle <- thisStart - prvIdx - 1 + charIdx[seq(from = prvIdx + 1, length.out = nSingle)] <- + seq(from = prv + 1, length.out = nSingle) + prv <- prv + nSingle + 1 + prvIdx <- thisStart + (comEscLen[j] - 1) + charIdx[thisStart:prvIdx] <- prv + } + nSingle <- nChars - prvIdx + charIdx[seq(from = prvIdx + 1, length.out = nSingle)] <- + seq(from = prv + 1, length.out = nSingle) + ## Each element of ltxChars should represent one character or + ## a space between words + strStart <- which(diff(c(0, charIdx)) > 0) + strStop <- c(strStart[-1] - 1, nChars) + ltxChars <- substring(ltxSingle[i], strStart, strStop) + } else { + ltxChars <- character(0) + } + ## stripChars: "Independently" do a part of what latexify() + ## does, i.e. remove control characters and use single spaces + ## only + stripChars <- + strsplit(gsub(multiSpaceClass, + " ", + gsub(controlClass, + "", + testStrings[i])), + "")[[1]] + ## Compare ltxChars and stripChars + checkEqualsNumeric(length(stripChars), length(ltxChars), + msg=sprintf("Number of characters correct (%.0f)", + i), + tolerance=0) + singleFlag <- nchar(ltxChars) == 1 + checkTrue(!any(grepl(specialClass, + ltxChars[singleFlag], useBytes=TRUE)), + msg=sprintf("No specials left unescaped (%.0f)", i)) + checkEquals(ltxChars[singleFlag], stripChars[singleFlag], + msg=sprintf("Normal characters preserved (%.0f)", i)) + specialMap[[i]] <- unique(cbind(stripChars[!singleFlag], + ltxChars[!singleFlag])) + } + ## specialMap becomes a combination of the unique rows across its + ## elements + specialMap <- do.call(rbind, specialMap) + specialMap <- unique(specialMap) + ## Check that special characters are mapped to LaTeX commands in a + ## consistent manner + checkEqualsNumeric(length(specialChars), nrow(specialMap), + msg="Correct number of character mappings", + tolerance=0) + checkTrue(all(specialChars %in% specialMap[, 1]), + msg="Each special character has a mapping") + ## A separate test for encoding conversion + latin1String <- "clich\xe9 ma\xf1ana" + Encoding(latin1String) <- "latin1" + utf8fy <- latexify(latin1String) + checkEquals("UTF-8", Encoding(utf8fy), + msg="Declared encoding is UTF-8") + checkEquals(as.raw(c(0x63, 0x6c, 0x69, 0x63, 0x68, 0xc3, 0xa9, 0x20, + 0x6d, 0x61, 0xc3, 0xb1, 0x61, 0x6e, 0x61)), + charToRaw(utf8fy), + msg="Conversion to UTF-8 NFC succeeded") +} + +test.latexDate <- function() { + dates <- Sys.Date() + round(runif(100, min = -1000, max = 1000)) + latexDates <- latexDate(dates) + checkEqualsNumeric(length(dates), length(latexDates), + msg="Length of output equals length of input", + tolerance=0) + splitDates <- strsplit(latexDates, ", ") + checkEqualsNumeric(rep(2, length(dates)), + vapply(splitDates, length, numeric(1)), + msg="Year at end, separated by comma and space", + tolerance=0) + monthsDays <- vapply(splitDates, "[[", character(1), 1) + yearStr <- vapply(splitDates, "[[", character(1), 2) + Years <- suppressWarnings(as.numeric(yearStr)) + checkTrue(all(is.finite(Years)), msg="Year is a number") + splitDates2 <- strsplit(monthsDays, " ") + checkEqualsNumeric(rep(2, length(dates)), + vapply(splitDates2, length, numeric(1)), + msg="Month and day separated by space", + tolerance=0) + Months <- match(vapply(splitDates2, "[[", character(1), 1), month.name) + checkTrue(all(is.finite(Months)), + msg="Month names match to entries in month.name") + monthStr <- sprintf("%02.0f", Months) + Days <- suppressWarnings(as.numeric(vapply(splitDates2, + "[[", character(1), 2))) + checkTrue(all(is.finite(Days)), msg="Day of month is a number") + dayStr <- sprintf("%02.0f", Days) + checkEquals(as.character(dates), + paste(yearStr, monthStr, dayStr, sep="-"), + msg="latexDate(x) matches x in ISO format") +} Property changes on: pkg/dplR/inst/unitTests/runit.utils.R ___________________________________________________________________ Added: svn:eol-style + native Modified: pkg/dplR/man/latexify.Rd =================================================================== --- pkg/dplR/man/latexify.Rd 2014-11-11 09:14:55 UTC (rev 914) +++ pkg/dplR/man/latexify.Rd 2014-11-17 21:01:12 UTC (rev 915) @@ -22,10 +22,13 @@ The function is intended for use with unformatted inline text. Newlines, tabs and other whitespace characters (\code{"[:space:]"} in - \link{regex}) are converted to spaces. Control character + \link{regex}) are converted to spaces. Control characters (\code{"[:cntrl:]"}) that are not whitespace are removed. Other - special characters are {, }, \, #, $, \%, ^, &, _, ~, \" and /. They - are converted to the corresponding LaTeX commands. + special characters are \sQuote{\{}, \sQuote{\}}, \sQuote{\\}, + \sQuote{#}, \sQuote{$}, \sQuote{\%}, \sQuote{^}, \sQuote{&}, + \sQuote{_}, \sQuote{~}, + \sQuote{"}, and \sQuote{/}. + They are converted to the corresponding LaTeX commands. Before applying the substitutions described above, input elements with \code{Encoding} set to \code{"bytes"} are printed and the result is @@ -35,12 +38,11 @@ This set includes tabs, newlines and control characters. The substitutions are then applied to the intermediate result. - Input elements with \code{"unknown"} encoding are assumed to be in the - current encoding. These and \code{"latin1"} encoded elements are - converted to UTF-8. + The result is converted to UTF-8 encoding, Normalization Form C + (NFC). - Suggested package loading commands in the document preamble - are:\preformatted{\usepackage[T1]{fontenc} \% required for " + Assuming that \samp{pdflatex} is used for compilation, suggested + package loading commands in the document preamble are: \preformatted{\usepackage[T1]{fontenc} \% required for " \usepackage[utf8]{inputenx} \% UTF-8 input encoding \input{ix-utf8enc.dfu} \% more supported characters} @@ -51,6 +53,8 @@ \references{ Pakin, S. (2009) The Comprehensive LaTeX Symbol List. \url{http://www.ctan.org/tex-archive/info/symbols/comprehensive} + + The Unicode Consortium. The Unicode Standard. \url{http://www.unicode.org/versions/latest/} } \author{ Mikko Korpela From noreply at r-forge.r-project.org Mon Nov 17 22:16:47 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 17 Nov 2014 22:16:47 +0100 (CET) Subject: [Dplr-commits] r916 - pkg/dplR Message-ID: <20141117211647.5FC0D18712C@r-forge.r-project.org> Author: mvkorpel Date: 2014-11-17 22:16:46 +0100 (Mon, 17 Nov 2014) New Revision: 916 Modified: pkg/dplR/DESCRIPTION Log: Added version requirement for stringi Modified: pkg/dplR/DESCRIPTION =================================================================== --- pkg/dplR/DESCRIPTION 2014-11-17 21:01:12 UTC (rev 915) +++ pkg/dplR/DESCRIPTION 2014-11-17 21:16:46 UTC (rev 916) @@ -20,7 +20,7 @@ Depends: R (>= 2.15.0) Imports: gmp (>= 0.5-2), graphics, grDevices, grid, stats, utils, digest (>= 0.2.3), lattice (>= 0.13-6), png (>= 0.1-1), - stringi, stringr (>= 0.4), XML (>= 2.1-0) + stringi (>= 0.2-2), stringr (>= 0.4), XML (>= 2.1-0) Suggests: Biobase, dichromat (>= 1.2-3), foreach, forecast, iterators, knitr, RColorBrewer, RUnit (>= 0.4.25), tikzDevice, waveslim Description: This package contains functions for performing tree-ring From noreply at r-forge.r-project.org Wed Nov 19 19:35:43 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 19 Nov 2014 19:35:43 +0100 (CET) Subject: [Dplr-commits] r917 - pkg/dplR Message-ID: <20141119183544.003E7186CCA@r-forge.r-project.org> Author: andybunn Date: 2014-11-19 19:35:43 +0100 (Wed, 19 Nov 2014) New Revision: 917 Modified: pkg/dplR/TODO Log: a new todo for andy Modified: pkg/dplR/TODO =================================================================== --- pkg/dplR/TODO 2014-11-17 21:16:46 UTC (rev 916) +++ pkg/dplR/TODO 2014-11-19 18:35:43 UTC (rev 917) @@ -1,3 +1,5 @@ +o[andybunn] Recode vignettes into markdown so as to have them on Rpubs? + o[mvkorpel] Add option for smooth CI curves from theoretical AR1 in redfit! * At the moment, in the crossdating functions where a user wants to compare a From noreply at r-forge.r-project.org Thu Nov 20 15:26:08 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 20 Nov 2014 15:26:08 +0100 (CET) Subject: [Dplr-commits] r918 - in pkg/dplR: . R inst/doc inst/unitTests man vignettes Message-ID: <20141120142608.233F51877EB@r-forge.r-project.org> Author: mvkorpel Date: 2014-11-20 15:26:07 +0100 (Thu, 20 Nov 2014) New Revision: 918 Modified: pkg/dplR/DESCRIPTION pkg/dplR/R/latexify.R pkg/dplR/inst/doc/math-dplR.Rnw.txt pkg/dplR/inst/doc/math-dplR.pdf pkg/dplR/inst/unitTests/runit.utils.R pkg/dplR/man/latexify.Rd pkg/dplR/vignettes/dplR.sty Log: * Improved latexify() and its test function, particularly w.r.t. handling of quotes. It is now possible to produce a test LaTeX document by manually running the test function test.latexify(testDocument=TRUE). * Because latexify() can now produce straight single quotes when the 'textcomp' LaTeX package is loaded (which is the default assumption in latexify()), the package is now included in dplR.sty and the pseudo vignette "math-dplR" Modified: pkg/dplR/DESCRIPTION =================================================================== --- pkg/dplR/DESCRIPTION 2014-11-19 18:35:43 UTC (rev 917) +++ pkg/dplR/DESCRIPTION 2014-11-20 14:26:07 UTC (rev 918) @@ -3,7 +3,7 @@ Type: Package Title: Dendrochronology Program Library in R Version: 1.6.1 -Date: 2014-11-17 +Date: 2014-11-20 Authors at R: c(person("Andy", "Bunn", role = c("aut", "cph", "cre", "trl"), email = "andy.bunn at wwu.edu"), person("Mikko", "Korpela", role = c("aut", "trl")), person("Franco", "Biondi", Modified: pkg/dplR/R/latexify.R =================================================================== --- pkg/dplR/R/latexify.R 2014-11-19 18:35:43 UTC (rev 917) +++ pkg/dplR/R/latexify.R 2014-11-20 14:26:07 UTC (rev 918) @@ -21,7 +21,9 @@ ## ## It seems that Sweave needs doublebackslash = TRUE ## but knitr needs doublebackslash = FALSE. -latexify <- function(x, doublebackslash=TRUE) { +latexify <- function(x, doublebackslash = TRUE, + quotes = c("straight", "curved"), + packages = c("fontenc", "textcomp")) { y <- as.character(x) ## Kludge for converting from "byte" to the current encoding ## in a way which preserves the hex notation. @@ -37,6 +39,9 @@ cat(y[encBytes], sep = "\n") y[encBytes] <- foo } + fontenc <- "fontenc" %in% packages + textcomp <- "textcomp" %in% packages + straightQuotes <- match.arg(quotes) == "straight" ## Remove control characters (not spaces!) y <- gsub("(?![[:space:]])[[:cntrl:]]", "", y, perl=TRUE) ## Convert any sequence of whitespace to a single space. This @@ -56,17 +61,43 @@ substitutions <- list(c("\\{", "\\\\{"), c("\\}", "\\\\}"), - c("\\\\(?!(\\{|\\}))", "\\\\textbackslash{}"), + c("\\\\(?!\\{|\\})", "\\\\textbackslash{}"), c("\\#", "\\\\#"), c("\\$", "\\\\$"), c("%", "\\\\%"), - c("\\^", "\\\\^{}"), + c("\\^", "\\\\textasciicircum{}"), c("&", "\\\\&"), c("_", "\\\\_"), - c("~", "\\\\~{}"), - c('"', "\\\\textquotedbl{}"), + c("~", "\\\\textasciitilde{}"), + if (textcomp && straightQuotes) { + c("'", "\\\\textquotesingle{}") + }, + c('"', if (fontenc && straightQuotes) { + "\\\\textquotedbl{}" + } else { + "\\\\textquotedblright{}" + }), c("/", "\\\\slash{}")) - for (subst in substitutions) { + if (isTRUE(l10n_info()[["MBCS"]])) { + ## The output of sQuote() and dQuote() may contain + ## non-ASCII quoting characters. If the input is ASCII, + ## it may be a surprise to the user that an UTF-8 input + ## encoding is then needed in LaTeX. Converting the + ## quotes to commands solves this problem. + substitutions <- + c(substitutions, + list(c("\u2018", "\\\\textquoteleft{}"), + c("\u2019", "\\\\textquoteright{}"), + c("\u201c", "\\\\textquotedblleft{}"), + c("\u201d", "\\\\textquotedblright{}"))) + } + ## Remove empty group after command when followed by a backslash + Letters <- paste(c(LETTERS, letters), collapse="") + substitutions <- c(substitutions, + list(c(sprintf("(\\\\[%s]+)\\{\\}(?=\\\\)", + Letters), "\\1"))) + + for (subst in substitutions[!vapply(substitutions, is.null, logical(1))]) { y <- gsub(subst[1], subst[2], y, perl = TRUE) } if (isTRUE(doublebackslash)) { Modified: pkg/dplR/inst/doc/math-dplR.Rnw.txt =================================================================== --- pkg/dplR/inst/doc/math-dplR.Rnw.txt 2014-11-19 18:35:43 UTC (rev 917) +++ pkg/dplR/inst/doc/math-dplR.Rnw.txt 2014-11-20 14:26:07 UTC (rev 918) @@ -65,6 +65,7 @@ @ \usepackage[T1]{fontenc} +\usepackage{textcomp} \usepackage[utf8]{inputenx} \usepackage[english]{babel} \usepackage{amsmath} Modified: pkg/dplR/inst/doc/math-dplR.pdf =================================================================== (Binary files differ) Modified: pkg/dplR/inst/unitTests/runit.utils.R =================================================================== --- pkg/dplR/inst/unitTests/runit.utils.R 2014-11-19 18:35:43 UTC (rev 917) +++ pkg/dplR/inst/unitTests/runit.utils.R 2014-11-20 14:26:07 UTC (rev 918) @@ -28,18 +28,27 @@ msg="IDs have a restricted character (4/16 choices) in one position") } -test.latexify <- function() { +test.latexify <- function(testDocument=FALSE) { ## Number of test strings ## (including one "extra difficult" case and one empty string) SAMP.SIZE <- 50 stopifnot(SAMP.SIZE >= 2) MIN.LENGTH <- 1 MAX.LENGTH <- 1000 + MAX.NCHAR <- 20 # maximum length of a "word" ## All ASCII characters except NUL (0) characters <- rawToChar(as.raw(1:127), multiple = TRUE) - ## LaTeX special characters must be converted to commands + ## LaTeX special characters. Some of these must be converted to + ## commands. Others (single and double quote) are converted to + ## commands or other characters for improved compatibility with + ## other packages or to get a particular glyph (upright quote) + ## instead of the default (curved quote). + ## + ## NOTE that the handling (what kind of treatment if any) of some + ## characters (currently single quote) depends on the (default) + ## arguments of latexify(). specialChars <- - c("{", "}", "\\", "#", "$", "%", "^", "&", "_", "~", "\"", "/") + c("{", "}", "\\", "#", "$", "%", "^", "&", "_", "~", "\"", "/", "'") specialStr <- paste(specialChars, collapse="") ## latexify() is designed to convert any sequence of space ## characters to a single regular space @@ -57,12 +66,15 @@ ## * The other elements consist of a random sample of characters. strStop <- cumsum(stringLengths) strStart <- strStop - (stringLengths - 1) + nSpaces <- round(0.2 * nTotal) # In addition to spaces in 'characters' testStrings <- - c(substring(paste(sample(rep(characters, length.out = nTotal)), + c(substring(paste(sample(c(rep(characters, + length.out = nTotal - nSpaces), + rep(" ", nSpaces))), collapse=""), strStart, strStop), - paste(c(specialChars, - rev(specialChars), - rep(specialChars, each=3), + paste(c(specialChars, " ", + rev(specialChars), " ", + unlist(lapply(lapply(specialChars,rep,3), c, " ")), paste(specialChars, " \t")), collapse=""), "") @@ -85,11 +97,11 @@ msg="No line breaks (double backslash)") Letters <- paste(c(LETTERS, letters), collapse="") textCommand <- sprintf("\\\\[%s]+", Letters) - commandAndGroup <- paste(textCommand, "\\{\\}", sep="") - commandsAt <- gregexpr(commandAndGroup, ltxSingle) + commandAndGroup <- paste(textCommand, "(\\{\\}|(?=\\\\))", sep="") + commandsAt <- gregexpr(commandAndGroup, ltxSingle, perl=TRUE) checkEquals(lapply(gregexpr(textCommand, ltxSingle), as.vector), lapply(commandsAt, as.vector), - msg="Command name is terminated with empty group") + msg="Command name is followed by empty group or backslash") escape <- sprintf("\\\\[^%s](\\{\\})?", Letters) escapesAt <- gregexpr(escape, ltxSingle) @@ -141,7 +153,9 @@ ## a space between words strStart <- which(diff(c(0, charIdx)) > 0) strStop <- c(strStart[-1] - 1, nChars) - ltxChars <- substring(ltxSingle[i], strStart, strStop) + ## Strip off empty group following a command + ltxChars <- sub(sprintf("([%s])\\{\\}$", Letters), "\\1", + substring(ltxSingle[i], strStart, strStop)) } else { ltxChars <- character(0) } @@ -180,7 +194,7 @@ tolerance=0) checkTrue(all(specialChars %in% specialMap[, 1]), msg="Each special character has a mapping") - ## A separate test for encoding conversion + ## A test for encoding conversion latin1String <- "clich\xe9 ma\xf1ana" Encoding(latin1String) <- "latin1" utf8fy <- latexify(latin1String) @@ -190,6 +204,84 @@ 0x6d, 0x61, 0xc3, 0xb1, 0x61, 0x6e, 0x61)), charToRaw(utf8fy), msg="Conversion to UTF-8 NFC succeeded") + ## A test for other than default quoting options + quoteString <- "\"It's five o'clock\", he said." + res1 <- latexify(quoteString, doublebackslash=FALSE) + res2 <- latexify(quoteString, quotes="curved", doublebackslash=FALSE) + res3 <- latexify(quoteString, packages=character(0), doublebackslash=FALSE) + res4 <- latexify(quoteString, packages="fontenc", doublebackslash=FALSE) + res5 <- latexify(quoteString, packages="textcomp", doublebackslash=FALSE) + exp2 <- gsub("\"", "\\\\textquotedblright{}", quoteString) + exp4 <- gsub("\"", "\\\\textquotedbl{}", quoteString) + exp5 <- gsub("'", "\\\\textquotesingle{}", exp2) + exp1 <- gsub("'", "\\\\textquotesingle{}", exp4) + checkEquals(exp1, res1, msg="Default straight quotes") + checkEquals(exp2, res2, msg="Curved quotes") + checkEquals(res2, res3, msg="Fallback to curved quotes") + checkEquals(exp4, res4, msg="Fallback to curved single quotes") + retVal <- checkEquals(exp5, res5, msg="Fallback to curved double quotes") + ## Check that non-ASCII quotes used by dQuote() and sQuote() are + ## converted to LaTeX commands + if (isTRUE(l10n_info()[["MBCS"]])) { + nestQuotes <- paste0("You said, \u201cHe said, ", + "\u2018Have a nice day.\u2019\u201d") + nq <- latexify(nestQuotes, doublebackslash=FALSE) + retVal <- + checkEquals(gsub("\\{\\}(?=\\\\)", "", + gsub("\u2018", "\\\\textquoteleft{}", + gsub("\u2019", "\\\\textquoteright{}", + gsub("\u201c", "\\\\textquotedblleft{}", + gsub("\u201d", + "\\\\textquotedblright{}", + nestQuotes)))), + perl=TRUE), + nq) + } + ## When used independently outside the test suite, the function + ## can create a test document + if (isTRUE(testDocument) && isTRUE(l10n_info()[["UTF-8"]])) { + preamble <- c("\\documentclass[a4paper]{article}", + "\\usepackage[T1]{fontenc}", + "\\usepackage{textcomp}", + "\\usepackage{parskip}", + "\\usepackage[utf8]{inputenx}", + "\\input{ix-utf8enc.dfu}") + id <- c(testStrings, latin1String, rep(quoteString, 5), nestQuotes) + extraInfo <- c(rep("", length(testStrings) + 1), + paste0(" (", c("default", "curved", "no packages", + "only fontenc", "only textcomp"), ")"), + "") + + ## Record how R prints inputDescription + inputDescription <- character(length(id)) # dummy line + tc <- textConnection("inputDescription", "w", local = TRUE) + sink(tc) + on.exit(sink()) + on.exit(close(tc), add = TRUE) + for (i in seq_along(id)) { + print(id[i]) + } + sink() + close(tc) + on.exit() + + allOutput <- c(ltxSingle, utf8fy, res1, res2, res3, res4, res5, nq) + filename <- tempfile(pattern = "latexify", fileext = ".tex") + co <- file(filename, open = "wt", encoding = "UTF-8") + writeLines(preamble, co) + writeLines("\\begin{document}", co) + writeLines("\\begin{enumerate}", co) + writeLines(paste0("% ", inputDescription, extraInfo, "\n", + "\\item\\relax ", allOutput, + "% ", seq_along(allOutput)), + co, sep = "\n\n") + writeLines("\\end{enumerate}", co) + writeLines("\\end{document}", co) + close(co) + filename + } else { + retVal + } } test.latexDate <- function() { Modified: pkg/dplR/man/latexify.Rd =================================================================== --- pkg/dplR/man/latexify.Rd 2014-11-19 18:35:43 UTC (rev 917) +++ pkg/dplR/man/latexify.Rd 2014-11-20 14:26:07 UTC (rev 918) @@ -10,13 +10,30 @@ used together with \samp{\Sexpr} in vignettes. } \usage{ -latexify(x, doublebackslash = TRUE) +latexify(x, doublebackslash = TRUE, + quotes = c("straight", "curved"), + packages = c("fontenc", "textcomp")) } \arguments{ \item{x}{ a \code{character} vector } \item{doublebackslash}{ a \code{logical} flag. If \code{TRUE}, backslashes in the output are doubled. It seems that Sweave needs \code{TRUE} and knitr \code{FALSE}. } + \item{quotes}{ a \code{character} string specifying how single and + double quotes (ASCII codes 39 and 34) in the input are + treated. The default is to use straight quotes. The other option + is to use curved right side (closing) quotes. Straight double + quotes are not available in the default OT1 font encoding of LaTeX. + Straight single quotes require the \dQuote{textcomp} package. See + \code{\var{packages}}. } + \item{packages}{ a \code{character} vector specifying the LaTeX + packages allowed. The use of some symbols in LaTeX requires + commands or characters made available by an add-on package. If a + package required for a given character is not marked as available, a + fallback solution is silently used. For example, curved quotes may + be used instead of straight quotes. Including \code{"fontenc"} in + the vector means that some other encoding than OT1 is going to be + used. } } \details{ @@ -38,11 +55,18 @@ This set includes tabs, newlines and control characters. The substitutions are then applied to the intermediate result. - The result is converted to UTF-8 encoding, Normalization Form C - (NFC). + The quoting functions \code{\link{sQuote}} and \code{\link{dQuote}} may + use non-ASCII quote characters, depending on the locale. Also these + quotes are converted to LaTeX commands. This means that the quoting + functions are safe to use with any LaTeX input encoding. + The result is converted to UTF-8 encoding, Normalization Form C (NFC). + Note that this function will not add any non-ASCII characters that + were not already present in the input. + Assuming that \samp{pdflatex} is used for compilation, suggested - package loading commands in the document preamble are: \preformatted{\usepackage[T1]{fontenc} \% required for " + package loading commands in the document preamble are: \preformatted{\usepackage[T1]{fontenc} \% no '"' in OT1 font encoding +\usepackage{textcomp} \% some symbols e.g. straight single quote \usepackage[utf8]{inputenx} \% UTF-8 input encoding \input{ix-utf8enc.dfu} \% more supported characters} Modified: pkg/dplR/vignettes/dplR.sty =================================================================== --- pkg/dplR/vignettes/dplR.sty 2014-11-19 18:35:43 UTC (rev 917) +++ pkg/dplR/vignettes/dplR.sty 2014-11-20 14:26:07 UTC (rev 918) @@ -1,11 +1,12 @@ % This file is part of dplR: Dendrochronology Program Library in R. % Written by Andy Bunn and Mikko Korpela. \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{dplR}[2014/04/11 Package for dplR vignettes] +\ProvidesPackage{dplR}[2014/11/20 Package for dplR vignettes] \RequirePackage{amsmath} \RequirePackage{amssymb} \RequirePackage[T1]{fontenc} +\RequirePackage{textcomp} \RequirePackage[english]{babel}[2000/01/28] \RequirePackage{booktabs} \RequirePackage{Sweave} From noreply at r-forge.r-project.org Fri Nov 21 09:59:07 2014 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 21 Nov 2014 09:59:07 +0100 (CET) Subject: [Dplr-commits] r919 - in pkg/dplR: . R Message-ID: <20141121085907.CBE741877EA@r-forge.r-project.org> Author: mvkorpel Date: 2014-11-21 09:59:07 +0100 (Fri, 21 Nov 2014) New Revision: 919 Modified: pkg/dplR/DESCRIPTION pkg/dplR/R/latexify.R Log: Using character classes to reduce the number of gsub() calls. A rather obvious optimization, but the inspiration to this came from the source code of knitr. Modified: pkg/dplR/DESCRIPTION =================================================================== --- pkg/dplR/DESCRIPTION 2014-11-20 14:26:07 UTC (rev 918) +++ pkg/dplR/DESCRIPTION 2014-11-21 08:59:07 UTC (rev 919) @@ -3,7 +3,7 @@ Type: Package Title: Dendrochronology Program Library in R Version: 1.6.1 -Date: 2014-11-20 +Date: 2014-11-21 Authors at R: c(person("Andy", "Bunn", role = c("aut", "cph", "cre", "trl"), email = "andy.bunn at wwu.edu"), person("Mikko", "Korpela", role = c("aut", "trl")), person("Franco", "Biondi", Modified: pkg/dplR/R/latexify.R =================================================================== --- pkg/dplR/R/latexify.R 2014-11-20 14:26:07 UTC (rev 918) +++ pkg/dplR/R/latexify.R 2014-11-21 08:59:07 UTC (rev 919) @@ -49,6 +49,9 @@ ## newline belongs to both groups. y <- gsub("[[:space:]]+", " ", y) ## Escape LaTeX special characters. + ## Some substitutions are mandatory, others affect matters such as + ## the rendering of the character in question (\textquote...) or + ## line breaks (\slash). ## Source: Scott Pakin (2009) The Comprehensive LaTeX Symbol List. ## Accessible through "texdoc symbols". ## Particularly section 8.6 "ASCII and Latin 1 quick reference". @@ -59,16 +62,11 @@ ## but not if followed by { or }. ## After that, the order does not matter. substitutions <- - list(c("\\{", "\\\\{"), - c("\\}", "\\\\}"), + list(c("([{}])", "\\\\\\1"), c("\\\\(?!\\{|\\})", "\\\\textbackslash{}"), - c("\\#", "\\\\#"), - c("\\$", "\\\\$"), - c("%", "\\\\%"), c("\\^", "\\\\textasciicircum{}"), - c("&", "\\\\&"), - c("_", "\\\\_"), c("~", "\\\\textasciitilde{}"), + c("([#$%&_])", "\\\\\\1"), if (textcomp && straightQuotes) { c("'", "\\\\textquotesingle{}") },