[Dplr-commits] r1090 - in pkg/dplR: . R man vignettes

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Apr 6 06:48:46 CEST 2018


Author: andybunn
Date: 2018-04-06 06:48:45 +0200 (Fri, 06 Apr 2018)
New Revision: 1090

Added:
   pkg/dplR/R/time.rwl.R
   pkg/dplR/man/time.rwl.Rd
Modified:
   pkg/dplR/ChangeLog
   pkg/dplR/DESCRIPTION
   pkg/dplR/NAMESPACE
   pkg/dplR/R/cms.R
   pkg/dplR/R/plotRings.R
   pkg/dplR/R/seg.plot.R
   pkg/dplR/man/bai.in.Rd
   pkg/dplR/man/bai.out.Rd
   pkg/dplR/man/fill.internal.NA.Rd
   pkg/dplR/man/hanning.Rd
   pkg/dplR/man/morlet.Rd
   pkg/dplR/man/plotRings.Rd
   pkg/dplR/man/print.redfit.Rd
   pkg/dplR/man/redfit.Rd
   pkg/dplR/man/rwi.stats.running.Rd
   pkg/dplR/man/seg.plot.Rd
   pkg/dplR/man/skel.plot.Rd
   pkg/dplR/man/wavelet.plot.Rd
   pkg/dplR/vignettes/chron-dplR.Rnw
   pkg/dplR/vignettes/intro-dplR.Rnw
   pkg/dplR/vignettes/timeseries-dplR.Rnw
   pkg/dplR/vignettes/xdate-dplR.Rnw
Log:
Added time.rwl and time.crn as convenience functions to get years out of crn and rwl. Changes to Rd files to demonstrate.

Modified: pkg/dplR/ChangeLog
===================================================================
--- pkg/dplR/ChangeLog	2018-03-24 21:01:46 UTC (rev 1089)
+++ pkg/dplR/ChangeLog	2018-04-06 04:48:45 UTC (rev 1090)
@@ -2,6 +2,13 @@
 
 - Note that Darwin Alexander Pucha Cofrep has been added as a developer to work on plotRings() etc.
 
+File: time.rwl.R
+----------------
+
+- Two convenience functions time.rwl and time.crn which extract the row.names of
+  rwl and crn objects as numerics. Used as a S3 method with class rwl and class crn.
+  This resulted in various changes to Rd files to make use of this capability.
+
 File: seg.plot.R
 ----------------
 

Modified: pkg/dplR/DESCRIPTION
===================================================================
--- pkg/dplR/DESCRIPTION	2018-03-24 21:01:46 UTC (rev 1089)
+++ pkg/dplR/DESCRIPTION	2018-04-06 04:48:45 UTC (rev 1090)
@@ -3,7 +3,7 @@
 Type: Package
 Title: Dendrochronology Program Library in R
 Version: 1.6.8
-Date: 2018-03-24
+Date: 2018-04-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", "cph", "trl")), person("Franco", "Biondi",

Modified: pkg/dplR/NAMESPACE
===================================================================
--- pkg/dplR/NAMESPACE	2018-03-24 21:01:46 UTC (rev 1089)
+++ pkg/dplR/NAMESPACE	2018-04-06 04:48:45 UTC (rev 1090)
@@ -52,10 +52,12 @@
        write.tucson, plot.rwl, interseries.cor, summary.rwl, plot.crn,
        insert.ring, delete.ring, xskel.ccf.plot, xskel.plot, latexify,
        latexDate, rasterPlot, treeMean, rwl.report, print.rwl.report, 
-       plotRings)
+       plotRings,time.rwl,time.crn)
 
 S3method(print, redfit)
 S3method(plot, rwl)
 S3method(plot, crn)
 S3method(summary, rwl)
 S3method(print, rwl.report)
+S3method(time, rwl)
+S3method(time, crn)

Modified: pkg/dplR/R/cms.R
===================================================================
--- pkg/dplR/R/cms.R	2018-03-24 21:01:46 UTC (rev 1089)
+++ pkg/dplR/R/cms.R	2018-04-06 04:48:45 UTC (rev 1090)
@@ -26,7 +26,7 @@
 
     ## divide each series by c curve and restore to cal years
     rwi <- rwl2
-    yrs <- as.numeric(row.names(rwi))
+    yrs <- time(rwi)
     c.vec <- rep(as.numeric(NA), n.col)
     names(c.vec) <- col.names
     if(c.hat.t){

Modified: pkg/dplR/R/plotRings.R
===================================================================
--- pkg/dplR/R/plotRings.R	2018-03-24 21:01:46 UTC (rev 1089)
+++ pkg/dplR/R/plotRings.R	2018-04-06 04:48:45 UTC (rev 1090)
@@ -1,7 +1,7 @@
 plotRings <- function(year, trwN, trwS = NA_real_,
-                      trwE = NA_real_, trwW = NA_real_, 
+                      trwE = NA_real_, trwW = NA_real_,
+                      length.unit = "mm",
                       animation = FALSE, 
-                      length.unit = "100 mm",
                       sys.sleep = 0.2, 
                       year.labels = TRUE, 
                       d2pith = NA,

Modified: pkg/dplR/R/seg.plot.R
===================================================================
--- pkg/dplR/R/seg.plot.R	2018-03-24 21:01:46 UTC (rev 1089)
+++ pkg/dplR/R/seg.plot.R	2018-04-06 04:48:45 UTC (rev 1090)
@@ -6,6 +6,7 @@
     }
     yr <- as.numeric(row.names(rwl))
     first.year <- as.matrix(apply(rwl, 2, yr.range, yr.vec=yr))[1, ]
+    last.year <- as.matrix(apply(rwl, 2, yr.range, yr.vec=yr))[2, ]
     neworder <- order(first.year, decreasing=FALSE)
     segs <- rwl[, neworder, drop=FALSE]
     n.col <- ncol(segs)

Added: pkg/dplR/R/time.rwl.R
===================================================================
--- pkg/dplR/R/time.rwl.R	                        (rev 0)
+++ pkg/dplR/R/time.rwl.R	2018-04-06 04:48:45 UTC (rev 1090)
@@ -0,0 +1,7 @@
+time.rwl <- function(x,...){
+  as.numeric(rownames(x))
+}
+
+time.crn <- function(x,...){
+  as.numeric(rownames(x))
+}


Property changes on: pkg/dplR/R/time.rwl.R
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: pkg/dplR/man/bai.in.Rd
===================================================================
--- pkg/dplR/man/bai.in.Rd	2018-03-24 21:01:46 UTC (rev 1089)
+++ pkg/dplR/man/bai.in.Rd	2018-04-06 04:48:45 UTC (rev 1090)
@@ -74,10 +74,10 @@
 data(gp.d2pith)
 foo <- bai.in(rwl = gp.rwl, d2pith = gp.d2pith)
 foo.crn <- chron(foo)
-yr <- as.numeric(rownames(foo.crn))
-plot(yr, foo.crn[, 1], type = "n",
+yrs <- time(foo.crn)
+plot(yrs, foo.crn[, 1], type = "n",
      xlab = "Year", ylab = expression(mm^2))
-lines(yr, foo.crn[, 1], col = "grey", lty = "dashed")
-lines(yr, ffcsaps(foo.crn[, 1], nyrs = 32), col = "red", lwd = 2)
+lines(yrs, foo.crn[, 1], col = "grey", lty = "dashed")
+lines(yrs, ffcsaps(foo.crn[, 1], nyrs = 32), col = "red", lwd = 2)
 }
 \keyword{ manip }

Modified: pkg/dplR/man/bai.out.Rd
===================================================================
--- pkg/dplR/man/bai.out.Rd	2018-03-24 21:01:46 UTC (rev 1089)
+++ pkg/dplR/man/bai.out.Rd	2018-04-06 04:48:45 UTC (rev 1090)
@@ -79,10 +79,10 @@
 gp.dbh2[, 2] <- (gp.dbh[, 2] - gp.dbh[, 3]) * 10
 bar <- bai.out(rwl = gp.rwl, diam = gp.dbh2)
 bar.crn <- chron(bar)
-yr <- as.numeric(rownames(bar.crn))
-plot(yr, bar.crn[, 1], type = "n",
+yrs <- time(bar.crn)
+plot(yrs, bar.crn[, 1], type = "n",
      xlab = "Year", ylab = expression(mm^2))
-lines(yr, bar.crn[, 1], col = "grey", lty = "dashed")
-lines(yr, ffcsaps(bar.crn[, 1], nyrs = 32), col = "red", lwd = 2)
+lines(yrs, bar.crn[, 1], col = "grey", lty = "dashed")
+lines(yrs, ffcsaps(bar.crn[, 1], nyrs = 32), col = "red", lwd = 2)
 }
 \keyword{ manip }

Modified: pkg/dplR/man/fill.internal.NA.Rd
===================================================================
--- pkg/dplR/man/fill.internal.NA.Rd	2018-03-24 21:01:46 UTC (rev 1089)
+++ pkg/dplR/man/fill.internal.NA.Rd	2018-04-06 04:48:45 UTC (rev 1090)
@@ -65,14 +65,14 @@
                   x8=c(rnorm(8), NA, NA),
                   x9=c(rnorm(5), NA, rnorm(3), NA))
 row.names(foo) <- 1901:1910
-
+class(foo) <- c("rwl","data.frame")
 fill.internal.NA(foo, fill=0)
 
 bar <- fill.internal.NA(foo, fill="Spline")
 baz <- fill.internal.NA(foo, fill="Linear")
 
 ## note differences in method "Spline" vs. "Linear"
-yrs <- as.numeric(row.names(foo))
+yrs <- time(foo)
 plot(yrs, foo$x7, type="b", lwd=3)
 lines(yrs, bar$x7, col="red", lwd=2)
 lines(yrs, baz$x7, col="green", lwd=1)

Modified: pkg/dplR/man/hanning.Rd
===================================================================
--- pkg/dplR/man/hanning.Rd	2018-03-24 21:01:46 UTC (rev 1089)
+++ pkg/dplR/man/hanning.Rd	2018-04-06 04:48:45 UTC (rev 1090)
@@ -30,7 +30,7 @@
 \examples{library(graphics)
 library(utils)
 data(ca533)
-yrs <- as.numeric(rownames(ca533))
+yrs <- time(ca533)
 y <- ca533[, 1]
 not.na <- !is.na(y)
 yrs <- yrs[not.na]

Modified: pkg/dplR/man/morlet.Rd
===================================================================
--- pkg/dplR/man/morlet.Rd	2018-03-24 21:01:46 UTC (rev 1089)
+++ pkg/dplR/man/morlet.Rd	2018-04-06 04:48:45 UTC (rev 1090)
@@ -49,7 +49,7 @@
 data(ca533)
 ca533.rwi <- detrend(rwl = ca533, method = "ModNegExp")
 ca533.crn <- chron(ca533.rwi, prefix = "CAM", prewhiten = FALSE)
-Years <- as.numeric(rownames(ca533.crn))
+Years <- time(ca533.crn)
 CAMstd <- ca533.crn[, 1]
 out.wave <- morlet(y1 = CAMstd, x1 = Years, dj = 0.1, siglvl = 0.99)
 }

Modified: pkg/dplR/man/plotRings.Rd
===================================================================
--- pkg/dplR/man/plotRings.Rd	2018-03-24 21:01:46 UTC (rev 1089)
+++ pkg/dplR/man/plotRings.Rd	2018-04-06 04:48:45 UTC (rev 1090)
@@ -110,7 +110,7 @@
 # with tree-ring series from Rothenburg data
 data("anos1")
 
-yrs <- as.numeric(rownames(anos1))
+yrs <- time(anos1)
 # Plot rings with data of two radii from same individual tree
 res <- plotRings(yrs, anos1[,4], trwW = anos1[,5],
                  species.name = "Cedrela odorata")
@@ -150,16 +150,17 @@
                   trw01.w = abs(rnorm(100, 10, 2.5)),  # West direction
                   trw01.e = abs(rnorm(100, 10, 2.5)),  # East direction
                   row.names = 1918:2017)
+class(trw) <- c("rwl","data.frame")
 
-year <- as.numeric(rownames(trw))
+yrs <- time(trw)
 
 # Default plot with 2, 3 and 4 radii
-res <- plotRings(year, trw[,1], trw[,2], trw[,3], trw[,4])
+res <- plotRings(yrs, trw[,1], trw[,2], trw[,3], trw[,4])
 
 # with d2pith values (see the hole before the first rings in the plot)
-res <- plotRings(year, trw[,1], trw[,2], trw[,3], trw[,4],
+res <- plotRings(yrs, trw[,1], trw[,2], trw[,3], trw[,4],
                  d2pith = 500)
-res <- plotRings(year, trw[,1], trw[,2], trw[,3], trw[,4],
+res <- plotRings(yrs, trw[,1], trw[,2], trw[,3], trw[,4],
                  d2pith = c(200, NA, NA, 50))
 
 }

Modified: pkg/dplR/man/print.redfit.Rd
===================================================================
--- pkg/dplR/man/print.redfit.Rd	2018-03-24 21:01:46 UTC (rev 1089)
+++ pkg/dplR/man/print.redfit.Rd	2018-04-06 04:48:45 UTC (rev 1090)
@@ -71,17 +71,16 @@
 }
 \examples{library(utils)
 data(ca533)
-t <- as.numeric(row.names(ca533))
+tm <- time(ca533)
 x <- ca533[[1]]
 idx <- which(!is.na(x))
-redf <- redfit(x[idx], t[idx], "time",
+redf <- redfit(x[idx], tm[idx], "time",
                nsim = 100, iwin = 0, ofac = 1, n50 = 1)
 print(redf)
 fname <- tempfile(fileext=".csv")
 print(fname) # tempfile used for output
 print(redf, csv.out = TRUE, file = fname)
 redftable <- read.csv(fname)
-
 unlink(fname) # remove the file
 }
 \keyword{ print }

Modified: pkg/dplR/man/redfit.Rd
===================================================================
--- pkg/dplR/man/redfit.Rd	2018-03-24 21:01:46 UTC (rev 1089)
+++ pkg/dplR/man/redfit.Rd	2018-04-06 04:48:45 UTC (rev 1090)
@@ -373,7 +373,7 @@
 
 library(utils)
 data(cana157)
-yrs <- as.numeric(rownames(cana157))
+yrs <- time(cana157)
 x <- cana157[, 1]
 redf.x <- redfit(x, nsim = 1000)
 

Modified: pkg/dplR/man/rwi.stats.running.Rd
===================================================================
--- pkg/dplR/man/rwi.stats.running.Rd	2018-03-24 21:01:46 UTC (rev 1089)
+++ pkg/dplR/man/rwi.stats.running.Rd	2018-04-06 04:48:45 UTC (rev 1090)
@@ -244,7 +244,7 @@
   gp.crn <- chron(gp.rwi)
   ## Running stats on the rwi with an window
   foo <- rwi.stats.running(gp.rwi, gp.ids, window.length = 80)
-  yrs <- as.numeric(rownames(gp.crn))
+  yrs <- time(gp.crn)
   bar <- data.frame(yrs = c(min(yrs), foo$mid.year, max(yrs)),
                     eps = c(NA, foo$eps, NA))
   par(mar = c(2, 2, 2, 2), mgp = c(1.1, 0.1, 0), tcl = 0.25,

Modified: pkg/dplR/man/seg.plot.Rd
===================================================================
--- pkg/dplR/man/seg.plot.Rd	2018-03-24 21:01:46 UTC (rev 1089)
+++ pkg/dplR/man/seg.plot.Rd	2018-04-06 04:48:45 UTC (rev 1090)
@@ -25,6 +25,6 @@
 \seealso{ \code{\link{spag.plot}} }
 \examples{library(utils)
 data(co021)
-seg.plot(co021, main = "Campito Mountain")
+seg.plot(co021)
 }
 \keyword{ hplot }

Modified: pkg/dplR/man/skel.plot.Rd
===================================================================
--- pkg/dplR/man/skel.plot.Rd	2018-03-24 21:01:46 UTC (rev 1089)
+++ pkg/dplR/man/skel.plot.Rd	2018-04-06 04:48:45 UTC (rev 1090)
@@ -79,7 +79,7 @@
 \examples{library(utils)
 data(co021)
 x <- co021[,33]
-x.yrs <- as.numeric(rownames(co021))
+x.yrs <- time(co021)
 x.name <- colnames(co021)[33]
 ## On a raw ring width series - undated
 skel.plot(x)
@@ -89,7 +89,7 @@
 library(grDevices)
 ## Try cross-dating
 y <- co021[, 11]
-y.yrs <- as.numeric(rownames(co021))
+y.yrs <- time(co021)
 y.name <- colnames(co021)[11]
 
 ## send to postscript - 3 pages total

Added: pkg/dplR/man/time.rwl.Rd
===================================================================
--- pkg/dplR/man/time.rwl.Rd	                        (rev 0)
+++ pkg/dplR/man/time.rwl.Rd	2018-04-06 04:48:45 UTC (rev 1090)
@@ -0,0 +1,36 @@
+\encoding{UTF-8}
+\name{time.rwl}
+\alias{time.rwl}
+\alias{time.crn}
+\title{
+  Return time values for rwl and crn objects
+}
+\description{
+  Returns the time values for rwl and crn objects.
+}
+\usage{
+\method{time}{rwl}(x, ...)
+\method{time}{crn}(x, ...)
+}
+\arguments{
+
+  \item{x}{ An object of class \code{"rwl"} or an aboject of class \code{"crn"}.  }
+
+  \item{\dots}{ Not used.  }
+}
+\value{
+  A \code{numeric} vector of time (typically in years) for the object. This is done via \code{as.numeric(rownames(x))} but has been asked for by users so many times that it is being included as a function.
+}
+\author{
+  Andy Bunn
+}
+\seealso{
+  \code{\link{read.rwl}}
+  \code{\link{read.crn}}
+}
+\examples{
+library(utils)
+data(co021)
+co021.yrs <- time(co021)
+}
+\keyword{ manip }


Property changes on: pkg/dplR/man/time.rwl.Rd
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: pkg/dplR/man/wavelet.plot.Rd
===================================================================
--- pkg/dplR/man/wavelet.plot.Rd	2018-03-24 21:01:46 UTC (rev 1089)
+++ pkg/dplR/man/wavelet.plot.Rd	2018-04-06 04:48:45 UTC (rev 1090)
@@ -99,7 +99,7 @@
 data(ca533)
 ca533.rwi <- detrend(rwl = ca533, method = "ModNegExp")
 ca533.crn <- chron(ca533.rwi, prefix = "CAM", prewhiten = FALSE)
-Years <- as.numeric(rownames(ca533.crn))
+Years <- time(ca533.crn)
 CAMstd <- ca533.crn[, 1]
 out.wave <- morlet(y1 = CAMstd, x1 = Years, p2 = 9, dj = 0.1,
                    siglvl = 0.99)

Modified: pkg/dplR/vignettes/chron-dplR.Rnw
===================================================================
--- pkg/dplR/vignettes/chron-dplR.Rnw	2018-03-24 21:01:46 UTC (rev 1089)
+++ pkg/dplR/vignettes/chron-dplR.Rnw	2018-04-06 04:48:45 UTC (rev 1090)
@@ -178,7 +178,7 @@
 wa082.ids <- autoread.ids(wa082)
 eps.cut <- 0.75 # An arbitrary EPS cutoff for demonstration
 wa082.rwi.stats <- rwi.stats.running(wa082.rwi, wa082.ids, window.length = 30)
-yrs <- as.numeric(rownames(wa082.crn))
+yrs <- time(wa082.crn)
 bar <- data.frame(yrs = c(min(yrs), wa082.rwi.stats$mid.year, max(yrs)),
                   eps = c(NA, wa082.rwi.stats$eps, NA))
 op <- par(no.readonly=TRUE)

Modified: pkg/dplR/vignettes/intro-dplR.Rnw
===================================================================
--- pkg/dplR/vignettes/intro-dplR.Rnw	2018-03-24 21:01:46 UTC (rev 1089)
+++ pkg/dplR/vignettes/intro-dplR.Rnw	2018-04-06 04:48:45 UTC (rev 1090)
@@ -313,7 +313,7 @@
 ## based on EPS. Running stats on the rwi with a window.
 foo <- rwi.stats.running(ca533.rwi, ca533.ids,
                          window.length = 80)
-yrs <- as.numeric(rownames(ca533.crn))
+yrs <- time(ca533.crn)
 bar <- data.frame(yrs = c(min(yrs), foo$mid.year, max(yrs)),
                   eps = c(NA, foo$eps, NA))
 par(mar = c(2, 2, 2, 2), mgp = c(1.1, 0.1, 0), tcl = 0.25,

Modified: pkg/dplR/vignettes/timeseries-dplR.Rnw
===================================================================
--- pkg/dplR/vignettes/timeseries-dplR.Rnw	2018-03-24 21:01:46 UTC (rev 1089)
+++ pkg/dplR/vignettes/timeseries-dplR.Rnw	2018-04-06 04:48:45 UTC (rev 1090)
@@ -236,7 +236,7 @@
 the result via \code{wavelet.plot}.
 
 <<e, fig=TRUE>>=
-yrs <- as.numeric(rownames(co021.crn))
+yrs <- time(co021.crn)
 out.wave <- morlet(y1 = dat, x1 = yrs, p2 = 8, dj = 0.1,
                    siglvl = 0.99)
 wavelet.plot(out.wave, useRaster=NA, reverse.y = TRUE)

Modified: pkg/dplR/vignettes/xdate-dplR.Rnw
===================================================================
--- pkg/dplR/vignettes/xdate-dplR.Rnw	2018-03-24 21:01:46 UTC (rev 1089)
+++ pkg/dplR/vignettes/xdate-dplR.Rnw	2018-04-06 04:48:45 UTC (rev 1090)
@@ -186,7 +186,7 @@
 
 <<d, fig=TRUE>>=
 win <- 1800:1960
-dat.yrs <- as.numeric(rownames(dat))
+dat.yrs <- time(dat)
 dat.trunc <- dat[dat.yrs %in% win, ]
 ccf.30 <- ccf.series.rwl(rwl=dat.trunc, series="643114", 
                          seg.length=30, bin.floor=50)



More information about the Dplr-commits mailing list