#'@title Create a PDF report for the HyperSAS data collection for a station or a transit
#'
#'@description
#'A PDF report is generated using knitr package facilities and a *.Rnw
#'template. It provides an efficent mean to visualise the data.
#'It can be called from the higher level function \code{\link{HyperSAS.go}}, or
#'run in the command line as along as SAS.raw.RData and RRS.RData have been
#'generated by \code{\link{process.HyperSAS}}.
#'
#'@param dirdat is the current directory path contaning the files to process.
#'@param TYPE is either equal to "STATION" or "TRANSIT" depending
#'whether the folder gather replicate Rrs of the same station, or the data
#'collected during the course of a ship transit. If the function is
#'called from \code{\link{HyperSAS.go}}, the TYPE will be read in the file named
#'directories.for.HyperSAS.dat. Otherwise the default is "STATION".
#'@param DIAGNOSTIC.PLOTS is a logical parameter indicating whether or not diagnostic plots are saved in PNG format.
#'It is used only when TYPE="TRANSIT".
#'The plots shows the temporal variability in Ed and tilt,
#'as well as the spectra for each Ed, Li and Lt recorded during the data acquisition.
#'Default is FALSE.
#'
#'@details
#'There is two templates located in the package data folder:
#'"HyperSAS_Station_TEMPLATE.Rnw" and "HyperSAS_Transit_TEMPLATE.Rnw".
#'This function will extract a number of informations from the current
#'data directory and RData files. Next it uses the brew package to update the Rnw files.
#'The Rnw files are converted into PDF using knitr package.
#'
#'@seealso \code{\link{process.HyperSAS}}, \code{\link{HyperSAS.go}}
#'@author Simon Bélanger
#'@export
#'@name create.HyperSAS.report
create.HyperSAS.report <- function(dirdat,
TYPE="STATION",
DIAGNOSTIC.PLOTS=FALSE){
if (TYPE == "STATION") {
report.template <- paste( Sys.getenv("R_HOCR_DATA_DIR"), "HyperSAS_Station_TEMPLATE.Rnw", sep = "/")
print("Use knirt report template located at:")
print(report.template)
# get information for the report
# extract Station name and date from the directory name
res=unlist(strsplit(dirdat, "/"))
for (i in 1:length(res)){
xx = str_locate(res[i], "_Station")
if (!is.na(xx[1])) {
datestation=unlist(strsplit(res[i], "_Station"))
# Remove "_" from station name to avoid error with Latex
if (str_detect(datestation[2], "_")) {
yy = unlist(strsplit(datestation[2], "_"))
Station = paste(yy, collapse=" ")
} else Station = datestation[2]
Date = datestation[1]
}
}
}
if (TYPE == "TRANSIT") {
report.template <- paste( Sys.getenv("R_HOCR_DATA_DIR"), "HyperSAS_Transit_TEMPLATE.Rnw", sep = "/")
print("Use knirt report template located at:")
print(report.template)
# get information for the report
# extract Station name and date from the directory name
res=unlist(strsplit(dirdat, "/"))
for (i in 1:length(res)){
xx = str_locate(res[i], "_Transit")
if (!is.na(xx[1])) {
datestation=unlist(strsplit(res[i], "_Transit"))
# Remove "_" from station name to avoid error with Latex
if (str_detect(datestation[2], "_")) {
yy = unlist(strsplit(datestation[2], "_"))
Transit = paste(yy, collapse=" ")
} else Transit = datestation[2]
Date = datestation[1]
}
}
}
reportname <- "RRS.plot.Rnw"
brew(report.template,reportname)
knit2pdf(reportname, quiet = T)
file.remove("RRS.plot.log")
file.remove("RRS.plot.aux")
file.remove("RRS.plot.tex")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.