Skip to content

Commit

Permalink
Merge pull request #303 from ncss-tech/suggest-sp
Browse files Browse the repository at this point in the history
Move {sp} to suggests
  • Loading branch information
brownag authored Oct 10, 2024
2 parents 07b8170 + 4d0216a commit dd3fce1
Show file tree
Hide file tree
Showing 30 changed files with 128 additions and 99 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Package: aqp
Version: 2.0.4
Version: 2.1.0
Title: Algorithms for Quantitative Pedology
Authors@R: c(person(given="Dylan", family="Beaudette", role = c("aut", "cre"), email = "dylan.beaudette@usda.gov"), person(given="Pierre", family="Roudier", email="roudierp@landcareresearch.co.nz", role = c("aut", "ctb")), person(given="Andrew", family="Brown", email="andrew.g.brown@usda.gov", role = c("aut", "ctb")))
Author: Dylan Beaudette [aut, cre], Pierre Roudier [aut, ctb], Andrew Brown [aut, ctb]
Maintainer: Dylan Beaudette <dylan.beaudette@usda.gov>
Depends: R (>= 3.5.0)
Imports: grDevices, graphics, stats, utils, methods, grid, lattice, cluster, sp, stringr, data.table, farver
Suggests: mvtnorm, colorspace, ape, soilDB, sf, latticeExtra, tactile, compositions, sharpshootR, markovchain, xtable, testthat, Gmedian, Hmisc, tibble, RColorBrewer, scales, digest, MASS, mpspline2, soiltexture, gower, knitr, rmarkdown, plyr
Imports: grDevices, graphics, stats, utils, methods, grid, lattice, cluster, stringr, data.table, farver
Suggests: mvtnorm, colorspace, ape, soilDB, sp, sf, latticeExtra, tactile, compositions, sharpshootR, markovchain, xtable, testthat, Gmedian, Hmisc, tibble, RColorBrewer, scales, digest, MASS, mpspline2, soiltexture, gower, knitr, rmarkdown, plyr
Description: The Algorithms for Quantitative Pedology (AQP) project was started in 2009 to organize a loosely-related set of concepts and source code on the topic of soil profile visualization, aggregation, and classification into this package (aqp). Over the past 8 years, the project has grown into a suite of related R packages that enhance and simplify the quantitative analysis of soil profile data. Central to the AQP project is a new vocabulary of specialized functions and data structures that can accommodate the inherent complexity of soil profile information; freeing the scientist to focus on ideas rather than boilerplate data processing tasks <doi:10.1016/j.cageo.2012.10.020>. These functions and data structures have been extensively tested and documented, applied to projects involving hundreds of thousands of soil profiles, and deeply integrated into widely used tools such as SoilWeb <https://casoilresource.lawr.ucdavis.edu/soilweb-apps>. Components of the AQP project (aqp, soilDB, sharpshootR, soilReports packages) serve an important role in routine data analysis within the USDA-NRCS Soil Science Division. The AQP suite of R packages offer a convenient platform for bridging the gap between pedometric theory and practice.
License: GPL (>= 3)
LazyLoad: yes
Expand Down
7 changes: 0 additions & 7 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,6 @@ exportMethods(trunc)
exportMethods(unique)
exportMethods(validSpatialData)
import(data.table)
importClassesFrom(sp,SpatialPoints)
importClassesFrom(sp,SpatialPointsDataFrame)
importFrom(cluster,daisy)
importFrom(cluster,pam)
importFrom(cluster,silhouette)
Expand Down Expand Up @@ -307,11 +305,6 @@ importFrom(methods,setOldClass)
importFrom(methods,setReplaceMethod)
importFrom(methods,slot)
importFrom(methods,slotNames)
importFrom(sp,"coordinates<-")
importFrom(sp,"proj4string<-")
importFrom(sp,SpatialPoints)
importFrom(sp,coordinates)
importFrom(sp,proj4string)
importFrom(stats,TukeyHSD)
importFrom(stats,aggregate)
importFrom(stats,aov)
Expand Down
12 changes: 8 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# aqp 2.0.4 (2024-10-10)
# aqp 2.1.0 (2024-10-10)
* added Munsell values of 8.5 and 9.5 to Munsell look up table and (interpolated) reference spectra (#318)
* `munsell2rgb()` now safely selects the closest Munsell value and chroma to those available in the package LUT
* new function `soilTextureColorPal()` for suggesting a color palette suitable for soil texture class
* **Breaking Change**: `@sp` slot of the SoilProfileCollection object, and dependency on sp package, has been removed.
* Any SoilProfileCollection objects previously written to file (.rda, .rds) with aqp <2.1.x will need to be rebuilt using `rebuildSPC()` due to changes to S4 object structure

# aqp 2.0.4 (2024-07-30)
* CRAN release
* ragged bottom lines in `plotSPC()` now adjusted as function of number of profiles and device width
* additional metadata from `plotSPC()` saved to `last_spc_plot` in `aqp.env`
* added Munsell values of 8.5 and 9.5 to Munsell LUT and (interpolated) reference spectra (#318)
* `munsell2rgb()` now safely selects the closest Munsell value and chroma to those available in the package LUT
* new function `soilTextureColorPal()` for suggesting a color palette suitable for soil texture class

# aqp 2.0.3 (2024-04-18)
* CRAN release
Expand Down
1 change: 0 additions & 1 deletion R/AAAA.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ aqp.env <- new.env(hash = TRUE, parent = parent.frame())
# register options for later use
.onLoad <- function(libname, pkgname) {
options(.aqp.show.n.cols = 10)

}

# no longer needed since it is imported
Expand Down
38 changes: 17 additions & 21 deletions R/Class-SoilProfileCollection.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,24 @@
#' @slot metadata list.
#' @slot horizons data.frame.
#' @slot site data.frame.
#' @slot sp SpatialPoints.
#' @slot diagnostic data.frame.
#' @slot restrictions data.frame.
#'
#' @details
#' After aqp 2.0.2, the `@sp` slot was removed from the SoilProfileCollection object. If you run into errors related to old object definitions, use `rebuildSPC()` on the problematic object.
#'
#' @aliases SoilProfileCollection-class
#' @rdname SoilProfileCollection-class
#' @importFrom sp SpatialPoints proj4string coordinates proj4string<- coordinates<-
#' @importClassesFrom sp SpatialPoints SpatialPointsDataFrame
setClass(
Class = 'SoilProfileCollection',
representation = representation(
idcol = 'character', # column name containing IDs
hzidcol = 'character', # column name containing unique horizon IDs
depthcols = 'character', # 2 element vector with column names for hz top, bottom

metadata = 'list', # list with key-value mapping

horizons = 'data.frame', # all horizons sorted by ID & top depth

site = 'data.frame', # data about the sampling sites

sp = 'SpatialPoints', # spatial data stored here, initialized as 'empty' sp object

# sp = 'NULL', # no longer used, formerly 'empty' sp object
diagnostic = 'data.frame',# (optional) diagnostic horizons are stored here
restrictions = 'data.frame' # (optional) restrictions are stored here
),
Expand All @@ -47,7 +43,7 @@ setClass(
top = numeric(0), bottom = numeric(0),
stringsAsFactors = FALSE),
site = data.frame(id = character(0), stringsAsFactors = FALSE),
sp = sp::SpatialPoints(data.frame(x = 0, y = 0))[-1, ],
# sp = NULL,
diagnostic = data.frame(stringsAsFactors = FALSE),
restrictions = data.frame(stringsAsFactors = FALSE)
),
Expand All @@ -61,18 +57,18 @@ setClass(
# c/o: https://gis.stackexchange.com/questions/291069/creating-empty-spatialpoints-or-spatialpointsdataframe-in-r
# old: new('SpatialPoints')
# new: SpatialPoints(data.frame(x = 0, y = 0))[-1,]
# new new: NULL

#' Constructor for the SoilProfileCollection object
#'
#' @param idcol character Profile ID Column Name
#' @param hzidcol character Horizon ID Column Name
#' @param depthcols character, length 2 Top and Bottom Depth Column Names
#' @param metadata list, metadata including data.frame class in use and depth units
#' @param horizons data.frame An object inheriting from data.frame containing Horizon data.
#' @param site data.frame An object inheriting from data.frame containing Site data.
#' @param sp SpatialPoints A SpatialPoints object. No longer used in aqp 2+, see `?initSpatial`
#' @param diagnostic data.frame An object inheriting from data.frame containing diagnostic feature data. Must contain profile ID. See \code{diagnostic_hz()}
#' @param restrictions data.frame An object inheriting from data.frame containing restrictive feature data. Must contain profile ID. See \code{restrictions()}
#' @param idcol character. Profile ID Column Name
#' @param hzidcol character. Horizon ID Column Name
#' @param depthcols character. length 2 Top and Bottom Depth Column Names
#' @param metadata list. metadata including data.frame class in use and depth units
#' @param horizons data.frame. An object inheriting from data.frame containing Horizon data.
#' @param site data.frame. An object inheriting from data.frame containing Site data.
#' @param diagnostic data.frame. An object inheriting from data.frame containing diagnostic feature data. Must contain profile ID. See \code{diagnostic_hz()}
#' @param restrictions data.frame. An object inheriting from data.frame containing restrictive feature data. Must contain profile ID. See \code{restrictions()}
#'
#' @description In general, one should use \code{depths()} to initiate a SoilProfileCollection object from data. However, sometimes there are instances where either an empty, or very specific, object is needed. If that is the case, the general constructor \code{SoilProfileCollection} is available.
#'
Expand Down Expand Up @@ -184,7 +180,7 @@ setClass(
stringsAsFactors = FALSE
),
site = data.frame(id = character(0), stringsAsFactors = FALSE),
sp = new('SpatialPoints'),
# sp = NULL,
diagnostic = data.frame(stringsAsFactors = FALSE),
restrictions = data.frame(stringsAsFactors = FALSE)) {

Expand Down Expand Up @@ -227,7 +223,7 @@ setClass(
metadata = metadata,
horizons = .as.data.frame.aqp(horizons, hzclass),
site = .as.data.frame.aqp(site, hzclass),
sp = sp,
# sp = sp,
diagnostic = .as.data.frame.aqp(diagnostic, hzclass),
restrictions = .as.data.frame.aqp(restrictions, hzclass)
)
Expand Down
18 changes: 13 additions & 5 deletions R/SoilProfileCollection-coercion.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' @docType methods
#' @rdname coercion-methods
#'
#' @examples
#' @examples
#' # load example data stored as SoilProfileCollection
#' data(sp5)
#'
Expand All @@ -30,11 +30,19 @@
#' sp5$x <- sp5$y <- rnorm(length(sp5))
#' initSpatial(sp5, crs = "OGC:CRS84") <- ~ x + y
#'
#' # SpatialPointsDataFrame output
#' str(as(sp5, 'SpatialPointsDataFrame'))
#' if (requireNamespace("sf")) {
#'
#' # sf output
#' str(as(sp5, 'sf'))
#'
#' # SpatialPointsDataFrame output
#' str(as(sp5, 'SpatialPointsDataFrame'))
#'
#' # SpatialPoints output
#' str(as(sp5, 'SpatialPoints'))
#'
#' }
#'
#' # SpatialPoints output
#' str(as(sp5, 'SpatialPoints'))
setAs("SoilProfileCollection", "list", function(from) {

# get slot names from prototype
Expand Down
2 changes: 1 addition & 1 deletion R/SoilProfileCollection-metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@

# transfer attributes https://github.com/ncss-tech/aqp/issues/204
customattr <- attributes(src)
customattr <- customattr[!names(customattr) %in% names(attributes(SoilProfileCollection()))]
customattr <- customattr[!names(customattr) %in% c("sp", names(attributes(SoilProfileCollection())))]
attributes(dest)[names(customattr)] <- attributes(src)[names(customattr)]

# original.order metadata no longer created, not transferred
Expand Down
12 changes: 4 additions & 8 deletions R/SoilProfileCollection-operators.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ setMethod("[", signature(x = "SoilProfileCollection"),
s <- s.all[s.i, , drop = FALSE]

# copy empty SpatialPoints object
sp <- x@sp
# sp <- x@sp

# subset diagnostic data
d <- diagnostic_hz(x)
Expand Down Expand Up @@ -307,7 +307,7 @@ setMethod("[", signature(x = "SoilProfileCollection"),
metadata = aqp::metadata(x),
horizons = .as.data.frame.aqp(h, aqp_df_class(x)),
site = .as.data.frame.aqp(s, aqp_df_class(x)),
sp = sp,
# sp = sp,
diagnostic = .as.data.frame.aqp(d, aqp_df_class(x)),
restrictions = .as.data.frame.aqp(r, aqp_df_class(x))
)
Expand Down Expand Up @@ -409,9 +409,7 @@ setMethod("[", signature(x = "SoilProfileCollection"),
# which is an error caused by RStudio? when doing tab completion
# with %>% operator on a SPC

setMethod("[[", signature(x = "SoilProfileCollection",
i = "ANY",
j = "ANY"),
setMethod("[[", signature(x = "SoilProfileCollection"),
function(x, i, j) {
if (length(i) == 1) {
# site names take precedence for those
Expand Down Expand Up @@ -446,9 +444,7 @@ setMethod("[[", signature(x = "SoilProfileCollection",
#' @aliases [[<-,SoilProfileCollection-method [[<-,SoilProfileCollection,ANY,ANY-method
#' @docType methods
#' @rdname doublebracket-set
setReplaceMethod("[[", signature(x = "SoilProfileCollection",
i = "ANY",
value = "ANY"),
setReplaceMethod("[[", signature(x = "SoilProfileCollection"),
function(x, i, value) {
lv <- length(value)
lx <- length(x)
Expand Down
19 changes: 16 additions & 3 deletions R/SoilProfileCollection-spatial.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ setGeneric("prj", function(object, ...)
#' @export
#' @seealso [initSpatial<-()]
#' @rdname SoilProfileCollection-crs
#' @aliases prj
#' @aliases prj proj4string
setMethod("prj", 'SoilProfileCollection',
function(object, ...) {
value <- metadata(object)$crs
Expand All @@ -26,7 +26,7 @@ setGeneric("prj<-", function(object, ..., value)
standardGeneric("prj<-"))

#' @description `prj()<-`: Set Coordinate Reference System metadata for the SoilProfileCollection
#' @aliases prj<-
#' @aliases prj<- proj4string<-
#' @rdname SoilProfileCollection-crs
#' @export
setReplaceMethod("prj", 'SoilProfileCollection',
Expand Down Expand Up @@ -65,6 +65,9 @@ setReplaceMethod("prj", 'SoilProfileCollection',
}
)

setGeneric("proj4string", function(obj)
standardGeneric("proj4string"))

#' @description `proj4string()`: (Deprecated) Get Coordinate Reference System as PROJ4 String
#' @rdname SoilProfileCollection-crs
#' @export
Expand All @@ -76,10 +79,14 @@ setMethod("proj4string", signature(obj = 'SoilProfileCollection'),
}
)

setGeneric("proj4string<-", function(obj, value)
standardGeneric("proj4string<-"))

#' @description `proj4string()<-`: (Deprecated) Set Coordinate Reference System metadata for the SoilProfileCollection
#' @rdname SoilProfileCollection-crs
#' @export
setReplaceMethod("proj4string", signature(obj = 'SoilProfileCollection'),
setReplaceMethod("proj4string", signature(obj = "SoilProfileCollection",
value = "ANY"),
function(obj, value) {
.Deprecated("prj<-", package = "aqp",
msg = "Methods based on sp class definitions have been deprecated and will be removed by October 1, 2023. See ?`prj<-`")
Expand Down Expand Up @@ -181,6 +188,9 @@ setMethod("getSpatial", signature(object = "SoilProfileCollection"),
return(as.matrix(sapply(cn, function(x) object[[x]])))
})

setGeneric("coordinates", function(obj)
standardGeneric("coordinates"))

#' @param obj A SoilProfileCollection
#' @export
#' @rdname initSpatial
Expand All @@ -193,6 +203,9 @@ setMethod("coordinates", signature(obj = "SoilProfileCollection"),
getSpatial(obj)
})

setGeneric("coordinates<-", function(object, value)
standardGeneric("coordinates<-"))

#' @rdname initSpatial
#' @export
#' @aliases coordinates<-
Expand Down
6 changes: 3 additions & 3 deletions R/combine.R
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ pbindlist <- function(l, new.idname = NULL, verbose = TRUE) {
o.s <- lapply(spc.list, '[[', 'site')
o.d <- lapply(spc.list, '[[', 'diagnostic')
o.r <- lapply(spc.list, '[[', 'restrictions')
o.sp <- lapply(spc.list, '[[', 'sp')
# o.sp <- lapply(spc.list, '[[', 'sp')

# generate new SPC components
# https://github.com/ncss-tech/aqp/issues/71
Expand Down Expand Up @@ -379,8 +379,8 @@ pbindlist <- function(l, new.idname = NULL, verbose = TRUE) {
}

# sp slot is deprecated; always empty/uninitialized now
o.sp <- new('SpatialPoints')

o.sp <- NULL
## sanity check: profile IDs should be unique
if (length(o.s[[new.pID]]) != length(unique(o.s[[new.pID]]))) {
stop('non-unique profile IDs detected')
Expand Down
3 changes: 1 addition & 2 deletions R/plotSPC.R
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,5 @@ plotSPC <- function(
#' @aliases plot,SoilProfileCollection-method plot,SoilProfileCollection,ANY-method
#' @rdname SoilProfileCollection-plotting-methods
#' @export
setMethod("plot", signature(x = "SoilProfileCollection",
y = "ANY"),
setMethod("plot", signature(x = "SoilProfileCollection"),
definition = {function(x, y, ...) plotSPC(x, ...)})
7 changes: 5 additions & 2 deletions R/rebuildSPC.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@
#' @seealso \code{\link{checkSPC}}
#' @export
rebuildSPC <- function(x) {

# break into pieces as list
x.list <- suppressWarnings(as(x, 'list'))

if (.hasSlot(x, "sp")) {
x.list <- x.list[!names(x.list) %in% "sp"]
}

# seed object for new SPC
res <- .as.data.frame.aqp(x.list$horizons, aqp_df_class(x))

Expand Down Expand Up @@ -103,7 +106,7 @@ rebuildSPC <- function(x) {

site(res) <- newsp
initSpatial(res) <- colnames(newsp)[2:3]
try(prj(res) <- x.list$sp@proj4string)
try(prj(res) <- x.list$sp@proj4string, silent = TRUE)
}
}
return(res)
Expand Down
Binary file modified data/SPC.with.overlap.rda
Binary file not shown.
Binary file modified data/jacobs2000.rda
Binary file not shown.
Binary file modified data/osd.rda
Binary file not shown.
Binary file modified data/rowley2019.rda
Binary file not shown.
Binary file modified data/sierraTransect.rda
Binary file not shown.
Binary file modified data/sp5.rda
Binary file not shown.
Binary file modified data/wilson2022.rda
Binary file not shown.
Loading

0 comments on commit dd3fce1

Please sign in to comment.