Skip to content

Commit

Permalink
Merge pull request #17 from karlropkins/main
Browse files Browse the repository at this point in the history
rsp_match_profile update - now in main version
  • Loading branch information
karlropkins authored Feb 21, 2025
2 parents eec5757 + 5ff8826 commit cad0d70
Show file tree
Hide file tree
Showing 34 changed files with 1,350 additions and 573 deletions.
10 changes: 7 additions & 3 deletions .Rproj.user/shared/notebooks/paths
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/ITS/projects/IPSOS/_______________latest/dts/banes/_techNote_IPSOSDefra_DTTrend_BANES_working_04.Rmd="EF13DF93"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/ITS/projects/Leeds_CPRPC/_working/climate_rough_01.Rmd="59DA471D"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/ITS/projects/NERC_TRANSISTION/events/Clean Air Networks Conference/naei estimate.Rmd="1BB48545"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/ITS/students/___studentPaper_AirQualityEvidence/coding/batch.coding.001.build.archives_v1.R="0F0B4BEB"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/_isolateContribution&breakPointAnalysis_KR_20230824.R="F18B98A3"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/_projects/_paper_01_IntroToRespeciate/MS Access Versions/speciate_5.2_0/test.R="FCE2E494"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/_projects/_print error/_codeNote_PrintError.Rmd="ED822FAC"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/_projects/_slides_02_CRC/r code 2/_marylebone_CRC_Slides_04.Rmd="5042A905"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/_projects/_slides_02_CRC/r code/_marylebone_CRC_Slides_04.Rmd="25A452C7"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/_projects/diagnostic ratios/_codeNote_DiagnosticRatios_202406.Rmd="D00DD16B"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/_projects/marylebone01/_template_match_notes_03.Rmd="0E46D0BD"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/_projects/marylebone03/_marylebone_analysis_pls_01.Rmd="F2B723A3"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/_projects/marylebone03/_marylebone_initial_observations_01.Rmd="E72195E5"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/_projects/marylebone03/_marylebone_metals_03.Rmd="D2C38DFE"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/_projects/match01/_match_notes_01.Rmd="A446C96C"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/_projects/match04/_match_notes_04.Rmd="86D39C7D"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/_working/_rsp_match/_codeNote_rsp_match.Rmd="2C6D68F7"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/test/data/specieurope/auto_update_specieurope/_codeNote_autoUpdateSpecieurope_202406.Rmd="3B5FC5B7"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/test/respeciate/.Rbuildignore="BAFF788D"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/test/respeciate/.Rproj.user/shared/notebooks/paths="DB89FCB7"
Expand All @@ -28,6 +28,7 @@ C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/test
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/test/respeciate/R/rsp.average.R="67ED42C3"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/test/respeciate/R/rsp.build.R="5A264727"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/test/respeciate/R/rsp.cluster.R="B197B439"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/test/respeciate/R/rsp.combine.R="B14AB6C9"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/test/respeciate/R/rsp.cor.R="DE099ED6"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/test/respeciate/R/rsp.eu.R="F043375D"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/test/respeciate/R/rsp.find.R="E59DFEFA"
Expand All @@ -45,4 +46,7 @@ C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/test
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/test/respeciate/README.Rmd="887EDA27"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/test/respeciate/README.md="D46A00DB"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/test/respeciate/man/SPECIATE.Rd="5BBCE9FA"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/test/respeciate/man/respeciate-package.Rd="C6302B15"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/test/respeciate/man/respeciate.generics.Rd="2897F12C"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/test/respeciate/man/rsp.match.Rd="ED3F1B42"
C:/Users/trakradmin/OneDrive - University of Leeds/Documents/pkg/respeciate/test/respeciate/man/rsp.plot.Rd="4A9AA108"
22 changes: 10 additions & 12 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
Package: respeciate
Title: Speciation profiles for gases and aerosols
Version: 0.3.2
Date: 2024-07-09
Description: Access to the air pollutant emission profiles in US EPA SPECIATE (v5.2) and
EU JRC SPECIEUROPE archives. More details in Simon et al (2010)
doi:10.5094/APR.2010.026 and Pernigotti et al (2016)
doi:10.1016/j.apr.2015.10.007, respectively.
Version: 0.3.5
Date: 2025-02-19
Description: Access to the air pollutant emission profiles in US EPA SPECIATE (v5.2) and EU JRC
SPECIEUROPE archives. More details in Simon et al (2010) doi:10.5094/APR.2010.026 and
Pernigotti et al (2016) doi:10.1016/j.apr.2015.10.007, respectively.
Type: Package
Authors@R: c( person(given = "Sergio", family = "Ibarra-Espinosa", role = c("aut",
"cre"), email = "sergio.ibarra@usp.br", comment = c(ORCID =
"0000-0002-3162-1905")), person(given = "Karl", family = "Ropkins", role =
c("aut"), email = "k.ropkins@its.leeds.ac.uk", comment = c(ORCID =
"0000-0002-0294-6997")) )
Authors@R: c( person(given = "Sergio", family = "Ibarra-Espinosa", role = c("aut", "cre"), email =
"sergio.ibarra@usp.br", comment = c(ORCID = "0000-0002-3162-1905")), person(given = "Karl",
family = "Ropkins", role = c("aut"), email = "k.ropkins@its.leeds.ac.uk", comment = c(ORCID =
"0000-0002-0294-6997")) )
License: MIT + file LICENSE
URL: https://github.com/atmoschem/respeciate
BugReports: https://github.com/atmoschem/respeciate/issues
LazyData: yes
Depends: R (>= 3.5.0)
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Encoding: UTF-8
Imports: data.table, lattice, latticeExtra
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export(rsp_build_x)
export(rsp_cor_species)
export(rsp_dcast)
export(rsp_dcast_profile)
export(rsp_dcast_profile_id)
export(rsp_dcast_species)
export(rsp_dcast_species_id)
export(rsp_distance_profile)
export(rsp_eu)
export(rsp_eu_pm10)
Expand All @@ -35,9 +37,11 @@ export(rsp_id_copy)
export(rsp_id_nalkane)
export(rsp_id_pah16)
export(rsp_info)
export(rsp_lbind)
export(rsp_match_profile)
export(rsp_melt_wide)
export(rsp_pad)
export(rsp_plot_match)
export(rsp_plot_profile)
export(rsp_plot_species)
export(rsp_pls_x)
Expand Down
17 changes: 16 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
# Release Notes Version 0.3

* [0.3.5]
* released 2025-02-19
* rebuild rsp_match_profile using data.table
* added rsp_plot_match (rsp_match_profile plot) output...

* [0.3.4]
* released 2024-08-06
* expended rsp_dcast to handle species, species.id, profile,
profile.id, and track all in all rsp_dcasts...

* [0.3.3]
* released 2024-07-13
* added draft rsp_lbind


* [0.3.2]
* released 2024-07-09
* added rsp_eu shortcut for SPECIEUROPE profiles

* updated logo; now SPECIATE + SPECIEUROPE

* [0.3.1]
* released 2024-06-12
Expand Down
2 changes: 1 addition & 1 deletion R/SPECIEUROPE.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' \describe{
#' \item{source}{The main SPECIEUROPE data set as of 2024/05/26.}
#' \item{ref}{The source citation, to be used whenever this data is used.}
#' \item{website}{The SPECIEUROPE project website}
#' \item{website}{The SPECIEUROPE project website link}
#' }
#' @source https://source-apportionment.jrc.ec.europa.eu/
#' @references Pernigotti, D., Belis, C.A., Spano, L., 2016. SPECIEUROPE: The
Expand Down
3 changes: 3 additions & 0 deletions R/respeciate-package.R
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
#' @keywords internal
#' @name respeciate-package
#' @aliases respeciate
"_PACKAGE"
NULL
51 changes: 49 additions & 2 deletions R/respeciate.generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,14 @@ print.respeciate <-


rsp.rep <- "respeciate"
if(class(.x)[1] == "rsp_sw"){
if(class(.x)[1] %in% c("rsp_sw", "rsp_siw")){
rsp.rep <- paste(rsp.rep, " (wide/species)", sep="")
.x <- rsp_melt_wide(.x, pad=FALSE, drop.nas = TRUE)
#####################################
#should we loose this if we start testing if missing below...
.x$.species.id <- .x$.species
}
if(class(.x)[1] == "rsp_pw"){
if(class(.x)[1] %in%c("rsp_pw", "rsp_piw")){
rsp.rep <- paste(rsp.rep, " (wide/profile)", sep="")
.x <- rsp_melt_wide(.x, pad=FALSE, drop.nas = TRUE)
#.x$PROFILE_NAME <- .x$PROFILE_CODE
Expand Down Expand Up @@ -743,6 +743,53 @@ merge.respeciate <-




##################################
# subset
##################################

# local subset for respeciate objects...
# allowing function pass

# example, would like this to work...
# subset(rsp_eu(), rsp_id_pah16)

# #' @rdname respeciate.generics
# #' @method subset respeciate
# #' @export

################################
# think about
################################

# wanted to do like above but subset.data.table not exported...
# and currently not working...
# maybe have a look at data.table subset and work up from that???

#
### example
## to do...

# subset.respeciate <-
# function(x, subset, ...){
# #setup
# .cls <- class(x)
# x <- data.table::as.data.table(x)
# s <- try(eval(substitute(subset), x, parent.frame()),
# silent=TRUE)
# if(class(s)[1]=="function"){
# subset <- s(x)
# } else {
# subset <- s
# }
# subset(x, subset, ...)
# out <- as.data.frame(x)
# class(out) <- .cls
# out
# }



################################
# not sure about this
################################
Expand Down
11 changes: 9 additions & 2 deletions R/rsp.build.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#' of these will need to be assigned.
#' @param species_name,species_id (\code{character}) The names of the columns
#' in \code{x} containing species name and identifiers, respectively. If not
#' already named according to \code{respeciate} conventions, at least one of these will
#' need to be assigned.
#' already named according to \code{respeciate} conventions, at least one of
#' these will need to be assigned.
#' @param value (\code{character}) The name of the column in \code{x}
#' containing measurement values. If not already named according to \code{respeciate}
#' conventions, this will need to be assigned.
Expand Down Expand Up @@ -102,6 +102,13 @@
# to retain the data type history
# and drop back to tibble rather than data.frame....

# wondering if .profile and .profile.id are wrong for rsp_x ???
# maybe they should be .sample and .sample.id
# but need special handler method
# for example:
# rsp_x-to-rsp code at start of most functions
# then a rsp-to-rsp_x at end (before all outputs if start code used...


#' @rdname rsp.build
#' @export
Expand Down
123 changes: 123 additions & 0 deletions R/rsp.combine.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#' @name rsp.combine
#' @title combining respeciate profiles
#' @aliases rsp_lbind

#' @description Functions to combining respeciate data sets.

#' @description \code{rsp_lbind} binds two or more \code{respeciate}-like
#' objects. The default option is to stack the supplied data sets (e.g.
#' \code{respeciate}, \code{data.frame}, etc) like \code{rbindlist}
#' in \code{data.table} (or row_bind in dplyr). This matches columns by name
#' before stacking the supplied data sets.

#' @param ... (various) This function is intended to be quite flexible. All
#' supplied arguments are tested and handled as follows: \code{respeciate}-like
#' objects are passed to \code{data.table::rbindlist} as a list to rbind using
#' \code{data.table} methods; Any other arguments that are valid
#' \code{rbindlist} arguments are passed on 'as is'; And, anything else is
#' (hopefully) ignored.

#' @return \code{rsp_lbind} attempts to return a single stacked version of the
#' supplied data sets. If it is successful, the (stacked) data set is typically
#' returned as a \code{respeciate} object or a \code{data.frame} with a warning
#' if it is missing columns \code{respeciate} expects.

## #' @note
## TO DO: want a statement here about why we are not going with a rbind method
## basically, it is a pain...
## ... if any of the data sets is a data.frame, and
## you get rbind.data.frame/default
## is some online discussion of its behaviour

## #' @seealso [link to data.table::rbindlist if we can do that...]
## not sure I am loading package

#' @references
#' Dowle M, Srinivasan A (2023). data.table: Extension of `data.frame`.
#' R package version 1.14.8, \url{https://CRAN.R-project.org/package=data.table}.

##########################################
# general NOTES
##########################################

# not loading all of data.table, see xxx.r...

######################
#rsp_lbind
######################

#' @rdname rsp.combine
#' @export

#issues
############################

# not finished

# bits of documentation to complete
# links to data.table::rbindlist need to be added
# in text and see also
# error messages need tidying
# currently not handling the class quite right
# ok for standard respeciate object,
# probably not for rsp_x
# definitely not for wides...
# stack, but probably breaks respeciate rules for
# data.frame, etc without expected respeciate names .... ?
# (see notes in function)

#think about...
#############################

# might need option to force object class
# option(s) to make errors/warning silent ????
# could we extend lbind to do cbind as well as rbind ????
# could we extend lbind to do merge as well ???

rsp_lbind <- function(...){

# setup
#####################################
.args <- list(...)

# ... handling 1: the data.sets
#####################################
# based on method in rsp() method v 0.3
# allows data.frames, respeciate objects, etc
.rsp <- lapply(.args, function(.rsp){
if(is.data.frame(.rsp)){ .rsp }})

#might want to think about respeciate handling ???
# if for example something is wide ???? or rsp_x ????

# rbindlist
###################################
# currently using loa-like approach...
# allowing only extra args formally declared in rbindlist
.refs <- names(formals(data.table::rbindlist))
.lbind <- modifyList(list(l=.rsp, fill=TRUE),
.args[names(.args) %in% .refs])
.bound.dt <- do.call(data.table::rbindlist, .lbind)
if(nrow(.bound.dt)==0){
stop("RSP> Nothing to list and rbind...",
call. = FALSE)
}

# output
###########################

# should this try to force class to that of first data set in call ???
# might make most sense ???

.rsp <- try(as.respeciate(.bound.dt), silent=TRUE)
if(class(.rsp)[1]=="try-error"){
warning("RSP> not obvious respeciate; returning as data.frame...",
call. = FALSE)
as.data.frame(.bound.dt)
} else {
.rsp
}
}



Loading

0 comments on commit cad0d70

Please sign in to comment.