diff --git a/NAMESPACE b/NAMESPACE index edc806f..90036e9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -41,6 +41,7 @@ export(normalise_sediment_OSPAR) export(plot_assessment) export(read_contaminants) export(read_data) +export(report_assessment) export(run_assessment) export(subset_assessment) export(tidy_data) diff --git a/R/reporting_functions.R b/R/reporting_functions.R index f68d93a..a4cb615 100644 --- a/R/reporting_functions.R +++ b/R/reporting_functions.R @@ -817,14 +817,13 @@ report_assessment <- function( info <- assessment_obj$info - timeSeries <- assessment_obj$timeSeries - + timeSeries <- assessment_obj$timeSeries # set up time series information: # - merge with station information # - add in additional useful variables # - subset if necessary - + timeSeries <- tibble::rownames_to_column(timeSeries, "series") timeSeries <- dplyr::left_join( @@ -851,13 +850,7 @@ report_assessment <- function( timeSeries$matrix <- "WT" } - if (!is.null(substitute(subset))) { - ok <- eval(substitute(subset), timeSeries, parent.frame()) - timeSeries <- timeSeries[ok, ] - row.names(timeSeries) <- NULL - } - - timeSeries <- tibble::column_to_rownames(timeSeries, "series") + timeSeries <- apply_subset(timeSeries, subset, parent.frame()) series_id <- row.names(timeSeries) @@ -904,8 +897,12 @@ report_assessment <- function( output_id <- gsub("\\", " ", output_id, fixed = TRUE) + package_dir = system.file(package = "harsat") + template_dir = file.path(package_dir, "markdown") + report_file <- file.path(template_dir, "report_assessment.Rmd") + rmarkdown::render( - "report_assessment.Rmd", + report_file, params = list( assessment_object = assessment_obj, series = id @@ -916,8 +913,7 @@ report_assessment <- function( }) invisible() -} - +} diff --git a/_pkgdown.yml b/_pkgdown.yml index ba8f531..69c92e2 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -22,10 +22,6 @@ navbar: - text: External file format href: articles/external-file-format.html - text: ------- - - text: "Resources" - - text: Datasets - href: articles/datasets.html - - text: ------- - text: "Examples" - text: HELCOM (read first) href: articles/example_HELCOM.html @@ -33,6 +29,12 @@ navbar: href: articles/example_OSPAR.html - text: AMAP external data href: articles/example_external_data.html + - text: ------- + - text: "Additional resources" + - text: Datasets + href: articles/datasets.html + - text: Report template + href: articles/report-template.html reference: - title: Primary functions diff --git a/report_assessment.Rmd b/inst/markdown/report_assessment.Rmd similarity index 100% rename from report_assessment.Rmd rename to inst/markdown/report_assessment.Rmd diff --git a/inst/markdown/report_assessment.css b/inst/markdown/report_assessment.css new file mode 100644 index 0000000..886bfd9 --- /dev/null +++ b/inst/markdown/report_assessment.css @@ -0,0 +1,3 @@ +li.gap { + margin-bottom: 3pt; +} diff --git a/report_assessment_status.Rmd b/inst/markdown/report_assessment_status.Rmd similarity index 100% rename from report_assessment_status.Rmd rename to inst/markdown/report_assessment_status.Rmd diff --git a/report_assessment_status_imposex.Rmd b/inst/markdown/report_assessment_status_imposex.Rmd similarity index 100% rename from report_assessment_status_imposex.Rmd rename to inst/markdown/report_assessment_status_imposex.Rmd diff --git a/report_assessment_trend.Rmd b/inst/markdown/report_assessment_trend.Rmd similarity index 100% rename from report_assessment_trend.Rmd rename to inst/markdown/report_assessment_trend.Rmd diff --git a/report_assessment_trend_imposex.Rmd b/inst/markdown/report_assessment_trend_imposex.Rmd similarity index 100% rename from report_assessment_trend_imposex.Rmd rename to inst/markdown/report_assessment_trend_imposex.Rmd diff --git a/man/apply_subset.Rd b/man/apply_subset.Rd new file mode 100644 index 0000000..11ebd26 --- /dev/null +++ b/man/apply_subset.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/graphics_functions.R +\name{apply_subset} +\alias{apply_subset} +\title{Apply subsetting to a time series} +\usage{ +apply_subset(timeSeries, subset, env = parent.frame()) +} +\arguments{ +\item{timeSeries}{a time series data frame} + +\item{subset}{(default \code{NULL}) either \code{NULL}, which selects all entries, or a logical, +which \code{TRUE} selects all entries and \code{FALSE} none of them, or an expression, which +will be evaluated in the context of the dataframe to generate a subsetting vector.} + +\item{env}{the calling environment for variable values.} +} +\description{ +This is an internal function that applies a subsetting function to a timeseries. +It is somewhat complex, due to way it is designed to be called. The subset is designed +to be passed either as a value (\code{NULL} or logical), as a expression, or as a variable +holding an expression. When it is an expression, it is applied in the context of the +timeseries data frame to generate a vector of booleans for subsetting. The complexity +comes from the way this implements lazy evaluation, so we cannot evaluate the expression +in the normal calling context. + +The function also removes row names, and converts the series column to row names. +} diff --git a/man/report_assessment.Rd b/man/report_assessment.Rd new file mode 100644 index 0000000..41a2311 --- /dev/null +++ b/man/report_assessment.Rd @@ -0,0 +1,39 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/reporting_functions.R +\name{report_assessment} +\alias{report_assessment} +\title{Reports the assessment of individual time series} +\usage{ +report_assessment( + assessment_obj, + subset = NULL, + output_dir = ".", + max_report = 100L +) +} +\arguments{ +\item{assessment_obj}{An assessment object resulting from a call to +run_assessment} + +\item{subset}{An optional vector specifying which timeseries are to be +reported. An expression will be evaluated in the timeSeries component of +assessment_obj; use 'series' to identify individual timeseries.} + +\item{output_dir}{The output directory for the assessment plots (possibly +supplied using 'file.path'). The default is the working directory. The +output directory must already exist.} + +\item{max_report}{The maximum number of reports that will be generated. +Defaults to 100. Each report is about 1MB in size and takes a few seconds +to run, so this prevents a ridiculous number of reports being created.} +} +\value{ +A series of html files with, for each time series, meta data, +plots of the data with the fitted assessment model, statistical summaries, +and a simple interpretation of the fitted model. +} +\description{ +Generates a series of html reports with, for each time series, meta data, +plots of the data with the fitted assessment model, statistical summaries, +and a simple interpretation of the fitted model. +} diff --git a/report_assessment.css b/report_assessment.css deleted file mode 100644 index 2a3a8f5..0000000 --- a/report_assessment.css +++ /dev/null @@ -1,7 +0,0 @@ -li.gap {margin-bottom: 3pt;} - -l - - - - diff --git a/tests/datasets/external-1/data/EXTERNAL_FO_PW_DATA_TINY.csv b/tests/datasets/external-1/data/EXTERNAL_FO_PW_DATA_TINY.csv new file mode 100644 index 0000000..3571b51 --- /dev/null +++ b/tests/datasets/external-1/data/EXTERNAL_FO_PW_DATA_TINY.csv @@ -0,0 +1,133 @@ +country,station_code,station_name,year,date,latitude,longitude,dephu,purpm,species,sex,subseries,n_individual,determinand,matrix,basis,value,unit,limit_detection,limit_quantification,uncertainty,unit_uncertainty,censoring,method_analysis,sample +Denmark,A902,Føroyskar hvalvágir ,2011,02/09/2011,62.15383,-7.15983,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.1,ng/g,,,,,<,UPLC-MS-MS,4310175 +Denmark,A902,Føroyskar hvalvágir ,2011,09/02/2011,62.15383,-7.15983,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.1,ng/g,,,,,<,UPLC-MS-MS,4310171 +Denmark,A902,Føroyskar hvalvágir ,2011,09/02/2011,62.15383,-7.15983,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.1,ng/g,,,,,,UPLC-MS-MS,4310171 +Denmark,A902,Føroyskar hvalvágir ,2011,02/09/2011,62.15383,-7.15983,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.5,ng/g,,,,,,UPLC-MS-MS,4310175 +Denmark,A902,Føroyskar hvalvágir ,2011,02/09/2011,62.15383,-7.15983,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.3,ng/g,,,,,,UPLC-MS-MS,4310175 +Denmark,A902,Føroyskar hvalvágir ,2012,10/07/2012,62.224293,-6.571586,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.4,ng/g,,,,,,UPLC-MS-MS,4310167 +Denmark,A902,Føroyskar hvalvágir ,2012,09/08/2012,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.7,ng/g,,,,,,UPLC-MS-MS,4310168 +Denmark,A902,Føroyskar hvalvágir ,2012,09/08/2012,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.3,ng/g,,,,,,UPLC-MS-MS,4310168 +Denmark,A902,Føroyskar hvalvágir ,2012,09/08/2012,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.5,ng/g,,,,,,UPLC-MS-MS,4310168 +Denmark,A902,Føroyskar hvalvágir ,2013,08/08/2013,62.05149,-7.155315,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.5,ng/g,,,,,<,UPLC-MS-MS,4310161 +Denmark,A902,Føroyskar hvalvágir ,2013,08/08/2013,62.05149,-7.155315,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.5,ng/g,,,,,<,UPLC-MS-MS,4310161 +Denmark,A902,Føroyskar hvalvágir ,2013,08/08/2013,62.05149,-7.155315,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.5,ng/g,,,,,<,UPLC-MS-MS,4310161 +Denmark,A902,Føroyskar hvalvágir ,2013,30/07/2013,62.23875,-6.810065,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.2,ng/g,,,,,,UPLC-MS-MS,4310160 +Denmark,A902,Føroyskar hvalvágir ,2013,30/07/2013,62.23875,-6.810065,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.5,ng/g,,,,,<,UPLC-MS-MS,4310160 +Denmark,A902,Føroyskar hvalvágir ,2013,30/07/2013,62.23875,-6.810065,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.5,ng/g,,,,,<,UPLC-MS-MS,4310160 +Denmark,A902,Føroyskar hvalvágir ,2013,30/07/2013,62.23875,-6.810065,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.1,ng/g,,,,,,UPLC-MS-MS,4310160 +Denmark,A902,Føroyskar hvalvágir ,2015,06/06/2015,62.04664,-7.186415,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.2,ng/g,,,,,,UPLC-MS-MS,4309941 +Denmark,A902,Føroyskar hvalvágir ,2015,06/06/2015,62.04664,-7.186415,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.7,ng/g,,,,,,UPLC-MS-MS,4309941 +Denmark,A902,Føroyskar hvalvágir ,2015,06/06/2015,62.04664,-7.186415,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.1,ng/g,,,,,<,UPLC-MS-MS,4309941 +Denmark,A902,Føroyskar hvalvágir ,2015,29/06/2015,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.2,ng/g,,,,,,UPLC-MS-MS,4309942 +Denmark,A902,Føroyskar hvalvágir ,2015,29/06/2015,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.4,ng/g,,,,,,UPLC-MS-MS,4309942 +Denmark,A902,Føroyskar hvalvágir ,2016,07/11/2016,62.1155,-7.04508,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.1,ng/g,,,,,<,UPLC-MS-MS,4308911 +Denmark,A902,Føroyskar hvalvágir ,2016,26/07/2016,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.4,ng/g,,,,,,UPLC-MS-MS,4308908 +Denmark,A902,Føroyskar hvalvágir ,2016,26/07/2016,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.3,ng/g,,,,,,UPLC-MS-MS,4308908 +Denmark,A902,Føroyskar hvalvágir ,2016,26/07/2016,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.8,ng/g,,,,,,UPLC-MS-MS,4308908 +Denmark,A902,Føroyskar hvalvágir ,2016,26/07/2016,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.3,ng/g,,,,,,UPLC-MS-MS,4308908 +Denmark,A902,Føroyskar hvalvágir ,2017,16/06/2017,62.00031,-6.77677,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,BB,W,0.04,ng/g,,,,,<,UPLC-MS-MS,4310328 +Denmark,A902,Føroyskar hvalvágir ,2017,16/06/2017,62.00031,-6.77677,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,BB,W,0.36,ng/g,,,19,%,,UPLC-MS-MS,4310328 +Denmark,A902,Føroyskar hvalvágir ,2017,26/06/2017,62.18833,-7.02733,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,BB,W,0.04,ng/g,,,,,<,UPLC-MS-MS,4310329 +Denmark,A902,Føroyskar hvalvágir ,2017,26/06/2017,62.18833,-7.02733,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,BB,W,0.04,ng/g,,,,,<,UPLC-MS-MS,4310329 +Denmark,A902,Føroyskar hvalvágir ,2017,29/06/2017,62.29236,-7.143775,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,BB,W,0.04,ng/g,,,,,<,UPLC-MS-MS,4310330 +Denmark,A902,Føroyskar hvalvágir ,2018,24/07/2018,62.00031,-6.77677,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,BB,W,0.4,ng/g,,,,,<,UPLC-MS-MS,4310342 +Denmark,A902,Føroyskar hvalvágir ,2018,24/07/2018,62.00031,-6.77677,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,BB,W,0.4,ng/g,,,,,<,UPLC-MS-MS,4310342 +Denmark,A902,Føroyskar hvalvágir ,2018,22/05/2018,62.185916,-6.753463,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,BB,W,0.49,ng/g,,,19,%,,UPLC-MS-MS,4310339 +Denmark,A902,Føroyskar hvalvágir ,2018,22/05/2018,62.185916,-6.753463,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,BB,W,0.83,ng/g,,,19,%,,UPLC-MS-MS,4310339 +Denmark,A902,Føroyskar hvalvágir ,2018,22/05/2018,62.185916,-6.753463,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,BB,W,0.43,ng/g,,,19,%,,UPLC-MS-MS,4310339 +Denmark,A902,Føroyskar hvalvágir ,2019,29/05/2019,62.00031,-6.77677,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.53,ng/g,,,9,%,,UPLC-MS-MS,4310347 +Denmark,A902,Føroyskar hvalvágir ,2019,27/08/2019,62.15383,-7.15983,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.17,ng/g,,,9,%,,UPLC-MS-MS,4310350 +Denmark,A902,Føroyskar hvalvágir ,2019,27/08/2019,62.15383,-7.15983,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.13,ng/g,,,9,%,,UPLC-MS-MS,4310350 +Denmark,A902,Føroyskar hvalvágir ,2019,27/08/2019,62.15383,-7.15983,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.15,ng/g,,,9,%,,UPLC-MS-MS,4310350 +Denmark,A902,Føroyskar hvalvágir ,2019,02/08/2019,62.18833,-7.02733,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.835,ng/g,,,9,%,,UPLC-MS-MS,4310349 +Denmark,A902,Føroyskar hvalvágir ,2020,16/10/2020,62.18833,-7.02733,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.05,ng/g,,,9,%,,UPLC-MS-MS,4310358 +Denmark,A902,Føroyskar hvalvágir ,2020,16/10/2020,62.18833,-7.02733,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.05,ng/g,,,9,%,,UPLC-MS-MS,4310358 +Denmark,A902,Føroyskar hvalvágir ,2020,16/10/2020,62.18833,-7.02733,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.07,ng/g,,,9,%,,UPLC-MS-MS,4310358 +Denmark,A902,Føroyskar hvalvágir ,2020,16/10/2020,62.18833,-7.02733,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.08,ng/g,,,9,%,,UPLC-MS-MS,4310358 +Denmark,A902,Føroyskar hvalvágir ,2020,16/10/2020,62.18833,-7.02733,,B~T~S~R,Globicephala melas,M,JV,1,PFOA,LI,W,0.07,ng/g,,,9,%,,UPLC-MS-MS,4310358 +Denmark,A902,Føroyskar hvalvágir ,2011,02/09/2011,62.15383,-7.15983,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,25.4,ng/g,,,,,,UPLC-MS-MS,4310175 +Denmark,A902,Føroyskar hvalvágir ,2011,09/02/2011,62.15383,-7.15983,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,53.4,ng/g,,,,,,UPLC-MS-MS,4310171 +Denmark,A902,Føroyskar hvalvágir ,2011,09/02/2011,62.15383,-7.15983,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,44.7,ng/g,,,,,,UPLC-MS-MS,4310171 +Denmark,A902,Føroyskar hvalvágir ,2011,02/09/2011,62.15383,-7.15983,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,69.8,ng/g,,,,,,UPLC-MS-MS,4310175 +Denmark,A902,Føroyskar hvalvágir ,2011,02/09/2011,62.15383,-7.15983,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,171.9,ng/g,,,,,,UPLC-MS-MS,4310175 +Denmark,A902,Føroyskar hvalvágir ,2012,10/07/2012,62.224293,-6.571586,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,79.8,ng/g,,,,,,UPLC-MS-MS,4310167 +Denmark,A902,Føroyskar hvalvágir ,2012,09/08/2012,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,100.7,ng/g,,,,,,UPLC-MS-MS,4310168 +Denmark,A902,Føroyskar hvalvágir ,2012,09/08/2012,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,82.8,ng/g,,,,,,UPLC-MS-MS,4310168 +Denmark,A902,Føroyskar hvalvágir ,2012,09/08/2012,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,86.7,ng/g,,,,,,UPLC-MS-MS,4310168 +Denmark,A902,Føroyskar hvalvágir ,2013,08/08/2013,62.05149,-7.155315,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,31.7,ng/g,,,,,,UPLC-MS-MS,4310161 +Denmark,A902,Føroyskar hvalvágir ,2013,08/08/2013,62.05149,-7.155315,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,282,ng/g,,,,,,UPLC-MS-MS,4310161 +Denmark,A902,Føroyskar hvalvágir ,2013,08/08/2013,62.05149,-7.155315,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,74.6,ng/g,,,,,,UPLC-MS-MS,4310161 +Denmark,A902,Føroyskar hvalvágir ,2013,30/07/2013,62.23875,-6.810065,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,68.4,ng/g,,,,,,UPLC-MS-MS,4310160 +Denmark,A902,Føroyskar hvalvágir ,2013,30/07/2013,62.23875,-6.810065,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,23.1,ng/g,,,,,,UPLC-MS-MS,4310160 +Denmark,A902,Føroyskar hvalvágir ,2013,30/07/2013,62.23875,-6.810065,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,26.6,ng/g,,,,,,UPLC-MS-MS,4310160 +Denmark,A902,Føroyskar hvalvágir ,2013,30/07/2013,62.23875,-6.810065,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,58.4,ng/g,,,,,,UPLC-MS-MS,4310160 +Denmark,A902,Føroyskar hvalvágir ,2015,06/06/2015,62.04664,-7.186415,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,51.7,ng/g,,,,,,UPLC-MS-MS,4309941 +Denmark,A902,Føroyskar hvalvágir ,2015,06/06/2015,62.04664,-7.186415,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,121.8,ng/g,,,,,,UPLC-MS-MS,4309941 +Denmark,A902,Føroyskar hvalvágir ,2015,06/06/2015,62.04664,-7.186415,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,28.9,ng/g,,,,,,UPLC-MS-MS,4309941 +Denmark,A902,Føroyskar hvalvágir ,2015,29/06/2015,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,64.1,ng/g,,,,,,UPLC-MS-MS,4309942 +Denmark,A902,Føroyskar hvalvágir ,2015,29/06/2015,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,110.7,ng/g,,,,,,UPLC-MS-MS,4309942 +Denmark,A902,Føroyskar hvalvágir ,2016,07/11/2016,62.1155,-7.04508,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,16.5,ng/g,,,,,,UPLC-MS-MS,4308911 +Denmark,A902,Føroyskar hvalvágir ,2016,26/07/2016,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,42.2,ng/g,,,,,,UPLC-MS-MS,4308908 +Denmark,A902,Føroyskar hvalvágir ,2016,26/07/2016,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,73.1,ng/g,,,,,,UPLC-MS-MS,4308908 +Denmark,A902,Føroyskar hvalvágir ,2016,26/07/2016,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,120.6,ng/g,,,,,,UPLC-MS-MS,4308908 +Denmark,A902,Føroyskar hvalvágir ,2016,26/07/2016,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,66.5,ng/g,,,,,,UPLC-MS-MS,4308908 +Denmark,A902,Føroyskar hvalvágir ,2017,16/06/2017,62.00031,-6.77677,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,BB,W,16.03,ng/g,,,24,%,,UPLC-MS-MS,4310328 +Denmark,A902,Føroyskar hvalvágir ,2017,16/06/2017,62.00031,-6.77677,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,BB,W,24.26,ng/g,,,24,%,,UPLC-MS-MS,4310328 +Denmark,A902,Føroyskar hvalvágir ,2017,26/06/2017,62.18833,-7.02733,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,BB,W,13.54,ng/g,,,24,%,,UPLC-MS-MS,4310329 +Denmark,A902,Føroyskar hvalvágir ,2017,26/06/2017,62.18833,-7.02733,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,BB,W,19.37,ng/g,,,24,%,,UPLC-MS-MS,4310329 +Denmark,A902,Føroyskar hvalvágir ,2017,29/06/2017,62.29236,-7.143775,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,BB,W,18.31,ng/g,,,24,%,,UPLC-MS-MS,4310330 +Denmark,A902,Føroyskar hvalvágir ,2018,24/07/2018,62.00031,-6.77677,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,BB,W,104,ng/g,,,24,%,,UPLC-MS-MS,4310342 +Denmark,A902,Føroyskar hvalvágir ,2018,24/07/2018,62.00031,-6.77677,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,BB,W,59.8,ng/g,,,24,%,,UPLC-MS-MS,4310342 +Denmark,A902,Føroyskar hvalvágir ,2018,22/05/2018,62.185916,-6.753463,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,BB,W,102,ng/g,,,24,%,,UPLC-MS-MS,4310339 +Denmark,A902,Føroyskar hvalvágir ,2018,22/05/2018,62.185916,-6.753463,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,BB,W,105,ng/g,,,24,%,,UPLC-MS-MS,4310339 +Denmark,A902,Føroyskar hvalvágir ,2018,22/05/2018,62.185916,-6.753463,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,BB,W,129,ng/g,,,24,%,,UPLC-MS-MS,4310339 +Denmark,A902,Føroyskar hvalvágir ,2019,29/05/2019,62.00031,-6.77677,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,120,ng/g,,,8,%,,UPLC-MS-MS,4310347 +Denmark,A902,Føroyskar hvalvágir ,2019,27/08/2019,62.15383,-7.15983,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,35,ng/g,,,8,%,,UPLC-MS-MS,4310350 +Denmark,A902,Føroyskar hvalvágir ,2019,27/08/2019,62.15383,-7.15983,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,63,ng/g,,,8,%,,UPLC-MS-MS,4310350 +Denmark,A902,Føroyskar hvalvágir ,2019,27/08/2019,62.15383,-7.15983,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,17,ng/g,,,8,%,,UPLC-MS-MS,4310350 +Denmark,A902,Føroyskar hvalvágir ,2019,02/08/2019,62.18833,-7.02733,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,134.5,ng/g,,,8,%,,UPLC-MS-MS,4310349 +Denmark,A902,Føroyskar hvalvágir ,2020,16/10/2020,62.18833,-7.02733,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,9.2,ng/g,,,8,%,,UPLC-MS-MS,4310358 +Denmark,A902,Føroyskar hvalvágir ,2020,16/10/2020,62.18833,-7.02733,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,11.6,ng/g,,,8,%,,UPLC-MS-MS,4310358 +Denmark,A902,Føroyskar hvalvágir ,2020,16/10/2020,62.18833,-7.02733,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,27.46,ng/g,,,8,%,,UPLC-MS-MS,4310358 +Denmark,A902,Føroyskar hvalvágir ,2020,16/10/2020,62.18833,-7.02733,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,20.13,ng/g,,,8,%,,UPLC-MS-MS,4310358 +Denmark,A902,Føroyskar hvalvágir ,2020,16/10/2020,62.18833,-7.02733,,B~T~S~R,Globicephala melas,M,JV,1,PFOS,LI,W,9.9,ng/g,,,8,%,,UPLC-MS-MS,4310358 +Denmark,A902,Føroyskar hvalvágir ,2011,09/02/2011,62.15383,-7.15983,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,12.3,ng/g,,,,,,UPLC-MS-MS,4310171 +Denmark,A902,Føroyskar hvalvágir ,2011,09/02/2011,62.15383,-7.15983,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,17.5,ng/g,,,,,,UPLC-MS-MS,4310171 +Denmark,A902,Føroyskar hvalvágir ,2011,02/09/2011,62.15383,-7.15983,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,17.7,ng/g,,,,,,UPLC-MS-MS,4310175 +Denmark,A902,Føroyskar hvalvágir ,2011,02/09/2011,62.15383,-7.15983,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,19.1,ng/g,,,,,,UPLC-MS-MS,4310175 +Denmark,A902,Føroyskar hvalvágir ,2011,02/09/2011,62.15383,-7.15983,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,13.5,ng/g,,,,,,UPLC-MS-MS,4310175 +Denmark,A902,Føroyskar hvalvágir ,2012,10/07/2012,62.224293,-6.571586,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,13.1,ng/g,,,,,,UPLC-MS-MS,4310167 +Denmark,A902,Føroyskar hvalvágir ,2012,09/08/2012,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,10.4,ng/g,,,,,,UPLC-MS-MS,4310168 +Denmark,A902,Føroyskar hvalvágir ,2012,09/08/2012,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,8,ng/g,,,,,,UPLC-MS-MS,4310168 +Denmark,A902,Føroyskar hvalvágir ,2012,09/08/2012,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,8.2,ng/g,,,,,,UPLC-MS-MS,4310168 +Denmark,A902,Føroyskar hvalvágir ,2013,08/08/2013,62.05149,-7.155315,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,18.3,ng/g,,,,,,UPLC-MS-MS,4310161 +Denmark,A902,Føroyskar hvalvágir ,2013,08/08/2013,62.05149,-7.155315,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,29.3,ng/g,,,,,,UPLC-MS-MS,4310161 +Denmark,A902,Føroyskar hvalvágir ,2013,08/08/2013,62.05149,-7.155315,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,13.7,ng/g,,,,,,UPLC-MS-MS,4310161 +Denmark,A902,Føroyskar hvalvágir ,2013,30/07/2013,62.23875,-6.810065,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,7.7,ng/g,,,,,,UPLC-MS-MS,4310160 +Denmark,A902,Føroyskar hvalvágir ,2013,30/07/2013,62.23875,-6.810065,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,8.5,ng/g,,,,,,UPLC-MS-MS,4310160 +Denmark,A902,Føroyskar hvalvágir ,2013,30/07/2013,62.23875,-6.810065,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,23,ng/g,,,,,,UPLC-MS-MS,4310160 +Denmark,A902,Føroyskar hvalvágir ,2013,30/07/2013,62.23875,-6.810065,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,12.8,ng/g,,,,,,UPLC-MS-MS,4310160 +Denmark,A902,Føroyskar hvalvágir ,2015,06/06/2015,62.04664,-7.186415,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,9.4,ng/g,,,,,,UPLC-MS-MS,4309941 +Denmark,A902,Føroyskar hvalvágir ,2015,06/06/2015,62.04664,-7.186415,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,7.5,ng/g,,,,,,UPLC-MS-MS,4309941 +Denmark,A902,Føroyskar hvalvágir ,2015,06/06/2015,62.04664,-7.186415,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,20.5,ng/g,,,,,,UPLC-MS-MS,4309941 +Denmark,A902,Føroyskar hvalvágir ,2015,29/06/2015,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,4.3,ng/g,,,,,,UPLC-MS-MS,4309942 +Denmark,A902,Føroyskar hvalvágir ,2015,29/06/2015,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,5,ng/g,,,,,,UPLC-MS-MS,4309942 +Denmark,A902,Føroyskar hvalvágir ,2016,07/11/2016,62.1155,-7.04508,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,6.9,ng/g,,,,,,UPLC-MS-MS,4308911 +Denmark,A902,Føroyskar hvalvágir ,2016,26/07/2016,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,6.1,ng/g,,,,,,UPLC-MS-MS,4308908 +Denmark,A902,Føroyskar hvalvágir ,2016,26/07/2016,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,15.9,ng/g,,,,,,UPLC-MS-MS,4308908 +Denmark,A902,Føroyskar hvalvágir ,2016,26/07/2016,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,13.4,ng/g,,,,,,UPLC-MS-MS,4308908 +Denmark,A902,Føroyskar hvalvágir ,2016,26/07/2016,62.30033,-6.523,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,7.3,ng/g,,,,,,UPLC-MS-MS,4308908 +Denmark,A902,Føroyskar hvalvágir ,2018,24/07/2018,62.00031,-6.77677,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,BB,W,13.2,ng/g,,,40,%,,UPLC-MS-MS,4310342 +Denmark,A902,Føroyskar hvalvágir ,2018,24/07/2018,62.00031,-6.77677,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,BB,W,31.8,ng/g,,,40,%,,UPLC-MS-MS,4310342 +Denmark,A902,Føroyskar hvalvágir ,2018,22/05/2018,62.185916,-6.753463,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,BB,W,17.3,ng/g,,,40,%,,UPLC-MS-MS,4310339 +Denmark,A902,Føroyskar hvalvágir ,2018,22/05/2018,62.185916,-6.753463,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,BB,W,17.7,ng/g,,,40,%,,UPLC-MS-MS,4310339 +Denmark,A902,Føroyskar hvalvágir ,2018,22/05/2018,62.185916,-6.753463,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,BB,W,17.7,ng/g,,,40,%,,UPLC-MS-MS,4310339 +Denmark,A902,Føroyskar hvalvágir ,2019,29/05/2019,62.00031,-6.77677,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,15,ng/g,,,1,%,,UPLC-MS-MS,4310347 +Denmark,A902,Føroyskar hvalvágir ,2019,27/08/2019,62.15383,-7.15983,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,4.9,ng/g,,,1,%,,UPLC-MS-MS,4310350 +Denmark,A902,Føroyskar hvalvágir ,2019,27/08/2019,62.15383,-7.15983,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,12,ng/g,,,1,%,,UPLC-MS-MS,4310350 +Denmark,A902,Føroyskar hvalvágir ,2019,27/08/2019,62.15383,-7.15983,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,11,ng/g,,,1,%,,UPLC-MS-MS,4310350 +Denmark,A902,Føroyskar hvalvágir ,2019,02/08/2019,62.18833,-7.02733,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,7.8,ng/g,,,1,%,,UPLC-MS-MS,4310349 +Denmark,A902,Føroyskar hvalvágir ,2020,16/10/2020,62.18833,-7.02733,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,19,ng/g,,,1,%,,UPLC-MS-MS,4310358 +Denmark,A902,Føroyskar hvalvágir ,2020,16/10/2020,62.18833,-7.02733,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,11.49,ng/g,,,1,%,,UPLC-MS-MS,4310358 +Denmark,A902,Føroyskar hvalvágir ,2020,16/10/2020,62.18833,-7.02733,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,5.08,ng/g,,,1,%,,UPLC-MS-MS,4310358 +Denmark,A902,Føroyskar hvalvágir ,2020,16/10/2020,62.18833,-7.02733,,B~T~S~R,Globicephala melas,M,JV,1,PFOSD,LI,W,12.07,ng/g,,,1,%,,UPLC-MS-MS,4310358 \ No newline at end of file diff --git a/tests/testthat/test-markdown.R b/tests/testthat/test-markdown.R new file mode 100644 index 0000000..d301a0d --- /dev/null +++ b/tests/testthat/test-markdown.R @@ -0,0 +1,77 @@ +library(rprojroot) +working_directory <- is_testthat$find_file() + +data_dir = file.path(working_directory, "..", "datasets", "external-1", "data") +info_dir = file.path(working_directory, "..", "datasets", "external-1", "information") + +library(rmarkdown) + +package_dir = system.file(package = "harsat") +template_dir = file.path(package_dir, "markdown") + +output_dir <- file.path(tempdir(), 'report-tests') +dir.create(output_dir, showWarnings = FALSE) + +call_read_data <- function(compartment = "biota", data_format = "external", purpose = "AMAP", + contaminants = "EXTERNAL_FO_PW_DATA_TINY.csv") { + read_data( + compartment = compartment, + purpose = purpose, + contaminants = contaminants, + stations = "EXTERNAL_AMAP_STATIONS.csv", + data_dir = data_dir, + data_format = data_format, + info_dir = info_dir + ) +} + +test_that('markdown reporting works', { + + biota_data <- call_read_data() + biota_data <- tidy_data(biota_data) + biota_timeseries <- create_timeseries(biota_data, get_basis = get_basis_most_common) + biota_assessment <- run_assessment(biota_timeseries) + + report_file <- file.path(template_dir, "report_assessment.Rmd") + output_file <- tempfile("plot", tmpdir = output_dir, fileext = c(".htm")) + + params = list( + assessment_object = biota_assessment, + series = 'A902 PFOA Globicephala melas LI JV' + ) + + rmarkdown::render( + report_file, + output_file = output_file, + params = params, + envir = new.env() + ) + + file.body <- readr::read_file(output_file) + + expect_true(base::grepl('Perfluorooctanoic', file.body, fixed = TRUE)) + expect_true(base::grepl('long-finned pilot whale', file.body, fixed = TRUE)) + expect_true(base::grepl('liver', file.body, fixed = TRUE)) + expect_true(base::grepl('Føroyskar hvalvágir', file.body, fixed = TRUE)) + + expect_true(base::grepl('Timeseries metadata', file.body, fixed = TRUE)) + expect_true(base::grepl('Assessment plot', file.body, fixed = TRUE)) + expect_true(base::grepl('Trend with data', file.body, fixed = TRUE)) + expect_true(base::grepl('Statistical analysis', file.body, fixed = TRUE)) + + ## In addition, we should also be able to run `report_assessment` + + report_assessment( + biota_assessment, + subset = NULL, + output_dir = output_dir + ) + + report.files <- list.files(output_dir, pattern = '\\.html$') + expect_setequal(report.files, c( + "A902 Faroe Islands Føroyskar hvalvágir PFOA Globicephala melas BB JV.html", + "A902 Faroe Islands Føroyskar hvalvágir PFOA Globicephala melas LI JV.html", + "A902 Faroe Islands Føroyskar hvalvágir PFOS Globicephala melas BB JV.html", + "A902 Faroe Islands Føroyskar hvalvágir PFOS Globicephala melas LI JV.html" + )) +}) diff --git a/tests/testthat/test-run-assessment.R b/tests/testthat/test-run-assessment.R new file mode 100644 index 0000000..6717e3d --- /dev/null +++ b/tests/testthat/test-run-assessment.R @@ -0,0 +1,34 @@ +library(rprojroot) +working_directory <- is_testthat$find_file() + +data_dir = file.path(working_directory, "..", "datasets", "external-1", "data") +info_dir = file.path(working_directory, "..", "datasets", "external-1", "information") + +call_read_data <- function(compartment = "biota", data_format = "external", purpose = "AMAP", + contaminants = "EXTERNAL_FO_PW_DATA_TINY.csv") { + read_data( + compartment = compartment, + purpose = purpose, + contaminants = contaminants, + stations = "EXTERNAL_AMAP_STATIONS.csv", + data_dir = data_dir, + data_format = data_format, + info_dir = info_dir + ) +} + +test_that('run_assessment works', { + biota_data <- call_read_data() + biota_data <- tidy_data(biota_data) + biota_timeseries <- create_timeseries(biota_data, get_basis = get_basis_most_common) + biota_assessment <- run_assessment(biota_timeseries) + + expect_equal(biota_assessment$info$compartment, 'biota') + expect_type(biota_assessment$timeSeries, 'list') + expect_type(biota_assessment$assessment, 'list') + expect_type(biota_assessment$assessment$`A902 PFOA Globicephala melas LI JV`, 'list') + expect_equal(biota_assessment$assessment$`A902 PFOA Globicephala melas LI JV`$method, 'linear') + expect_equal(biota_assessment$assessment$`A902 PFOA Globicephala melas LI JV`$convergence, 0) + expect_equal(biota_assessment$assessment$`A902 PFOA Globicephala melas BB JV`$method, 'none') + expect_equal(biota_assessment$assessment$`A902 PFOA Globicephala melas BB JV`$convergence, 0) +}) diff --git a/vignettes/report-template.Rmd b/vignettes/report-template.Rmd new file mode 100644 index 0000000..7f5f532 --- /dev/null +++ b/vignettes/report-template.Rmd @@ -0,0 +1,80 @@ +--- +title: "Report template usage" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Report template usage} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +The package includes a report template that may help you generate a +report for a given assessment. This is installed as a file `report_assessment.Rmd` +in a directory `markdown`, so to use it, you'll need to use `system.file()` to +find the template file. + +You can use this report tempate in two different ways: + +## Through `report_assessment` + +The easiest way to generate reports is in bulk, as follows: + +```r +## Do whatever you need to get the assessment object +... +assessment <- run_assessment(timeseries) + +report_assessment( + biota_assessment, + subset = NULL, + output_dir = my_output_dir +) +``` + +This will generate all the reports, although you can pass a subsetting +expression (just like with `plot_assessment`) to select which +individual assessments you want reports on. The reports are written +as HTML files into the given output directory. + +## Directly through R Markdown + +In this case, your usage will typically look a bit like this: + +```r +library(rmarkdown) + + +## Do whatever you need to get the assessment object +... +assessment <- run_assessment(timeseries) + +## Locate the report file +package_dir = system.file(package = "harsat") +template_dir = file.path(package_dir, "markdown") +report_file <- file.path(template_dir, "report_assessment.Rmd") + +## Create a new filename for the output file, here we just +## put it in a temporary file, but you'll usually want something +## more persistent. +output_file <- tempfile("plot", fileext = c(".htm")) + +## Choose what you want to report. Pick the series you want to +## report like this. +params = list( + assessment_object = assessment, + series = 'A902 PFOA Globicephala melas LI JV' +) + +## Generate the report -- note the use of `new.env()` to make a +## nice clean enviroment containing only the parameters you pass, +## as above. +rmarkdown::render( + report_file, + output_file = output_file, + params = params, + envir = new.env() +) +``` + +Note that because this is R Markdown, you can do this as a child +document from another template. You can also control the output +format, generating PDF, for example.