diff --git a/.Rbuildignore b/.Rbuildignore index 348879a2..a1a5175e 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -8,7 +8,6 @@ compile.* .vscode ^_pkgdown\.yml$ ^docs$ -^doc$ ^pkgdown$ ^\.github$ ^Meta$ @@ -18,3 +17,4 @@ compile.* ^man-roxygen ^README\.Rmd$ logo.png +^vignettes/articles$ diff --git a/.gitignore b/.gitignore index 7e9bd16a..64e818ae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,57 @@ -.Rproj.user +# History files .Rhistory +.Rapp.history + +# Session Data files .RData +.RDataTmp + +# User-specific files .Ruserdata + +# Example code in package build process +*-Ex.R + +# Output files from R CMD build +/*.tar.gz + +# Output files from R CMD check +/*.Rcheck/ + +# RStudio files +.Rproj.user/ + +# produced vignettes +vignettes/*.html +vignettes/*.pdf + +# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 +.httr-oauth + +# knitr and R markdown default cache directories +*_cache/ +/cache/ + +# Temporary files created by R markdown +*.utf8.md +*.knit.md + +# R Environment Variables +.Renviron + +# pkgdown site +docs/ + +# translation temp files +po/*~ + +# RStudio Connect folder +rsconnect/ +docs + +# other .DS_Store Pmetrics.Rcheck/ -#build Archived PACKAGES.gz PACKAGES.rds @@ -15,16 +62,13 @@ src/registerDynamicSymbol.o src/Pmetrics.dll PmetricsGit.Rproj inst/compiledFortran/ -.DS_Store src/symbols.rds tests/testthat/Runs/ ..Rcheck/ .vscode/ .Rd2pdf65996/ other/ -.Rprofile Examples -.Rdata .httr-oauth inst/rust/template/* inst/options/PMoptions.json diff --git a/DESCRIPTION b/DESCRIPTION index 851e34ee..1893c5cb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -62,14 +62,11 @@ Suggests: curl, data.table, devtools, - doParallel, - foreach, ggpubr, htmltools, knitr, mclust, pandoc, - parallel, patchwork, PmetricsData, progress, diff --git a/R/SIMparse.R b/R/SIMparse.R index ce67fa97..2e8ec78c 100644 --- a/R/SIMparse.R +++ b/R/SIMparse.R @@ -31,8 +31,6 @@ #' will be a list of PMsim objects, which can be plotted or otherwise accessed using standard list #' referencing, e.g. `simlist[[1]]`, `simlist[[2]]`, etc. #' @param quiet Suppress messages -#' @param parallel Runs in parallel mode. Defaults to true if multiple files are to be parsed, otherwise false. -#' Can be overridden by specifying \code{TRUE} or \code{FALSE}. #' @return If one file is parsed or multiple files are parsed and combined, the return will be a list with five items, of class \emph{PMsim}. #' If multiple files are parsed and not combined, then the return will be a *PM_simlist* of \emph{PMsim} objects. #' \item{obs }{An data frame of simulated observations with 4 columns: id, time, out, outeq. @@ -57,28 +55,28 @@ #' @seealso [PM_result], [PM_sim], [SIMrun] #' @export -SIMparse <- function(file, include, exclude, combine = F, quiet = F, parallel) { +SIMparse <- function(file, include, exclude, combine = F, quiet = F) { processfile <- function(n) { out <- readLines(allfiles[n]) - nsim <- as.numeric(strparse("[[:digit:]]+", out[grep(" THE NO. OF SIMULATED SUBJECTS", out)])) - nout <- as.numeric(strparse("[[:digit:]]+", out[grep(" THE NO. OF OUTPUT EQUATIONS", out)])) - nobs <- as.numeric(strparse("[[:digit:]]+", out[grep(" VALUES FOR EACH OUTPUT EQUATION", out)])) + nsim <- as.numeric(stringr::str_extract(out[grep(" THE NO. OF SIMULATED SUBJECTS", out)], "[[:digit:]]+")) + nout <- as.numeric(stringr::str_extract(out[grep(" THE NO. OF OUTPUT EQUATIONS", out)], "[[:digit:]]+")) + nobs <- as.numeric(stringr::str_extract(out[grep(" VALUES FOR EACH OUTPUT EQUATION", out)], "[[:digit:]]+")) i <- grep("CONTAIN THE SIMULATED OBSERVED$", out) times <- as.numeric(scan(allfiles[n], skip = i + 6, n = nobs + 1, what = "character", quiet = T)[-1]) - - + + # get compartment amounts and outeq concentrations for each output # places for compartment amounts amtlines <- grep("COMPARTMENT NO", out) + 1 # number of compartments ncomp <- length(amtlines) - - + + # places for observations obslines <- grep("OUTPUT EQUATION NO", out) + 1 # skip observed assay noise obslines <- obslines[-(1:nout)] - + # id is a block of 1:nsim repeated for each observation, all repeated for each compartment # time is a block of the times repeated for each subject, all repeated for each compartment # amt all amounts @@ -95,7 +93,7 @@ SIMparse <- function(file, include, exclude, combine = F, quiet = F, parallel) { } else { amt <- NA } - + # id is a block of 1:nsim repeated for each observation, all repeated for each output # time is a block of the times repeated for each subject, all repeated for each output # out is all observations @@ -109,10 +107,10 @@ SIMparse <- function(file, include, exclude, combine = F, quiet = F, parallel) { outeq = rep(1:nout, each = nsim * nobs) ) obs$out[obs$out == -99] <- NA - - + + # get simulated parameter values - + i <- grep("PARAMETER VALUES FOR ALL THE SUBJECTS.", out) parNames <- unlist(strsplit(out[i + 2], " +"))[-1] parValues <- t(sapply( @@ -122,10 +120,10 @@ SIMparse <- function(file, include, exclude, combine = F, quiet = F, parallel) { parValues <- data.frame(parValues) names(parValues) <- parNames names(parValues)[names(parValues) == "SUBJ."] <- "id" - - + + # get means and covariances of entire simulated set - + i <- grep("BECAUSE OF PARAMETER BOUNDARY RESTRICTIONS", out) if (length(i) > 0) { totalSets <- as.numeric(scan(allfiles[1], what = "character", skip = i, nlines = 1, quiet = T, strip.white = T)[1]) @@ -152,15 +150,15 @@ SIMparse <- function(file, include, exclude, combine = F, quiet = F, parallel) { } names(totalMeans) <- parNames[-1] if (length(parValues) > 2) dimnames(totalCov) <- list(parNames[-1], parNames[-1]) - + return(list(obs = obs, amt = amt, parValues = parValues, totalSets = totalSets, totalMeans = totalMeans, totalCov = totalCov)) } # end of processfile function - - # starttime <- proc.time() + if (missing(file)) { cat("Please provide filename of Pmetrics simulation output file(s).\n") return() } + # extract pattern from strings strparse <- function(pattern, x) { match <- regexpr(pattern, x, perl = T) # perl=T required for the lookahead @@ -168,13 +166,13 @@ SIMparse <- function(file, include, exclude, combine = F, quiet = F, parallel) { stop <- match[1] + attr(match, "match.length") - 1 return(substr(x, start, stop)) } - + # separate files if more than one files <- unlist(strsplit(file, ",")) # remove leading and trailing spaces files <- sub("^[[:blank:]]*", "", files) files <- sub("[[:blank:]]*$", "", files) - + # check that wildcard-generated list does not include outdated files # if out-of-order files are found, the user has the option to include them, exclude them, or abort nfilepar <- length(files) @@ -209,7 +207,7 @@ SIMparse <- function(file, include, exclude, combine = F, quiet = F, parallel) { } # end of check list of files generated by wildcard block } # end of IF wildcard used block } # end of filecheck cycle - + allfiles <- unique(Sys.glob(files)) # unique to exclude duplicates simnum <- as.numeric(sapply(allfiles, function(x) strparse("([[:digit:]]+)(?!.*[[:digit:]])", x))) # new reg exp matches the last number in filename rather than the first; "run5out1.txt" will now return 1 rather than 5 @@ -221,73 +219,24 @@ SIMparse <- function(file, include, exclude, combine = F, quiet = F, parallel) { allfiles <- allfiles[-exclude] } allfiles <- setdiff(allfiles, tobeignored) # delete files that are to be ignored from the date check - + nfiles <- length(allfiles) if (nfiles == 0) { stop("No files found.\n") } - if (missing(parallel)) { - if (nfiles > 1) { - parallel <- T - } else { - parallel <- F - } - } - - if (parallel) { - no_cores <- parallel::detectCores() - } + + + # process return objects - # initialize return objects - simlist <- list() if (!quiet) { - cat(paste("\nProcessing ", nfiles, " simulated data file(s)", sep = "")) - if (parallel) cat(" in parallel on ", no_cores, " cores.", sep = "") - cat("\n") + cat(paste("\nProcessing ", nfiles, " simulated data file(s).\n", sep = "")) flush.console() } - if (!quiet & !parallel) { - pb <- txtProgressBar(min = 0, max = nfiles, style = 3) - } - - par1 <- requireNamespace("doParallel", quietly = TRUE) - par2 <- requireNamespace("foreach", quietly = TRUE) - par3 <- requireNamespace("parallel", quietly = TRUE) - - if(!all(c(par1, par2, par3))){ #if any above packages are missing - - cat(paste0(crayon::green("NOTE: "), "Install the following package(s) for parallel processing: ", - crayon::blue(paste(c("doParallel", "foreach", "parallel")[c(!par1, !par2, !par3)], collapse = ", ")), - ".\n")) - - parallel <- FALSE - - } - + #map through files in pseudo-parallel; full parallel removed as actually longer + simlist <- purrr::pmap(list(1:nfiles), processfile, .progress = list(type = "tasks", name = "Files") ) - - if (parallel) { - cl <- parallel::makeCluster(no_cores, setup_timeout = 0.5) - # May 8, 2020 remove the second argument when bug fixed in Rstudio - doParallel::registerDoParallel(cl) - simlist <- foreach::foreach(n = 1:nfiles, .verbose = F) %dopar% { - processfile(n) - } - parallel::stopCluster(cl) - } else { - for (n in 1:nfiles) { - simlist[[n]] <- processfile(n) - if (!quiet) { - setTxtProgressBar(pb, n) - } - } - if (!quiet) { - close(pb) - } - } - # combine obs if requested if (combine & nfiles > 1) { if (!quiet) { @@ -299,7 +248,7 @@ SIMparse <- function(file, include, exclude, combine = F, quiet = F, parallel) { simlist[[x]]$obs$id <- paste(simlist[[x]]$obs$id, sprintf("%02d", x), sep = ".") simlist[[x]] }) - + obs <- do.call(rbind, lapply(simlist, function(x) x$obs)) amt <- do.call(rbind, lapply(simlist, function(x) x$amt)) parValues <- do.call(rbind, lapply(simlist, function(x) x$parValues)) @@ -309,7 +258,7 @@ SIMparse <- function(file, include, exclude, combine = F, quiet = F, parallel) { totalCov <- Reduce("+", lapply(simlist, function(x) x$totalCov * x$totalSets)) / totalSets simlist <- list(obs = obs, amt = amt, parValues = parValues, totalSets = totalSets, totalMeans = totalMeans, totalCov = totalCov) } - + # return simlist if (nfiles > 1) { # more than one file if (combine) { # combined @@ -329,9 +278,6 @@ SIMparse <- function(file, include, exclude, combine = F, quiet = F, parallel) { message <- paste(paste("\nThe following file was successfully parsed: ", paste(allfiles, collapse = ", "), "\n", sep = "")) } - utils::Rprof(NULL) - # runningtime <- proc.time()-starttime if (!quiet) cat(message) - # if(!quiet) cat(message,"Running time: ", runningtime[3], sep="") return(simlist) } diff --git a/_pkgdown.yml b/_pkgdown.yml index ffe344ee..e113c04b 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -42,7 +42,7 @@ home: reference: - title: R6 objects desc: Create Pmetrics R6 objects -- contents: +- contents: - starts_with("PM_") - ab - additive @@ -53,6 +53,7 @@ reference: - msd - proportional - build_model + - build_plot - title: Make functions desc: Functions for making Pmetrics objects - contents: @@ -65,7 +66,7 @@ reference: - MM_opt - title: Plot desc: Functions for plotting Pmetrics output -- contents: +- contents: - starts_with("plot") - ab_line - add_shapes @@ -129,6 +130,7 @@ reference: - editPMoptions - movePMoptions - update_gfortran + - getPMdata - title: Reference desc: Reference functions - contents: diff --git a/man/SIMparse.Rd b/man/SIMparse.Rd index 4ee28077..c642dc1b 100644 --- a/man/SIMparse.Rd +++ b/man/SIMparse.Rd @@ -4,7 +4,7 @@ \alias{SIMparse} \title{Parse Pmetrics Simulator Output} \usage{ -SIMparse(file, include, exclude, combine = F, quiet = F, parallel) +SIMparse(file, include, exclude, combine = F, quiet = F) } \arguments{ \item{file}{An output file or files of the simulator in the current working directory, or the full @@ -25,9 +25,6 @@ will be a list of PMsim objects, which can be plotted or otherwise accessed usin referencing, e.g. \code{simlist[[1]]}, \code{simlist[[2]]}, etc.} \item{quiet}{Suppress messages} - -\item{parallel}{Runs in parallel mode. Defaults to true if multiple files are to be parsed, otherwise false. -Can be overridden by specifying \code{TRUE} or \code{FALSE}.} } \value{ If one file is parsed or multiple files are parsed and combined, the return will be a list with five items, of class \emph{PMsim}. diff --git a/vignettes/Citations.bib b/vignettes/articles/Citations.bib similarity index 100% rename from vignettes/Citations.bib rename to vignettes/articles/Citations.bib diff --git a/vignettes/Data/ObjectsLegacy.csv b/vignettes/articles/Data/ObjectsLegacy.csv similarity index 100% rename from vignettes/Data/ObjectsLegacy.csv rename to vignettes/articles/Data/ObjectsLegacy.csv diff --git a/vignettes/Data/ObjectsR6.csv b/vignettes/articles/Data/ObjectsR6.csv similarity index 100% rename from vignettes/Data/ObjectsR6.csv rename to vignettes/articles/Data/ObjectsR6.csv diff --git a/vignettes/Data/PM_result.xlsx b/vignettes/articles/Data/PM_result.xlsx similarity index 100% rename from vignettes/Data/PM_result.xlsx rename to vignettes/articles/Data/PM_result.xlsx diff --git a/vignettes/Data/R6_Legacy_compare.xlsx b/vignettes/articles/Data/R6_Legacy_compare.xlsx similarity index 100% rename from vignettes/Data/R6_Legacy_compare.xlsx rename to vignettes/articles/Data/R6_Legacy_compare.xlsx diff --git a/vignettes/Data/RLcomp_data.csv b/vignettes/articles/Data/RLcomp_data.csv similarity index 100% rename from vignettes/Data/RLcomp_data.csv rename to vignettes/articles/Data/RLcomp_data.csv diff --git a/vignettes/Data/RLcomp_other.csv b/vignettes/articles/Data/RLcomp_other.csv similarity index 100% rename from vignettes/Data/RLcomp_other.csv rename to vignettes/articles/Data/RLcomp_other.csv diff --git a/vignettes/Data/RLcomp_valid.csv b/vignettes/articles/Data/RLcomp_valid.csv similarity index 100% rename from vignettes/Data/RLcomp_valid.csv rename to vignettes/articles/Data/RLcomp_valid.csv diff --git a/vignettes/Data/fortran1.csv b/vignettes/articles/Data/fortran1.csv similarity index 100% rename from vignettes/Data/fortran1.csv rename to vignettes/articles/Data/fortran1.csv diff --git a/vignettes/Data/fortran2.csv b/vignettes/articles/Data/fortran2.csv similarity index 100% rename from vignettes/Data/fortran2.csv rename to vignettes/articles/Data/fortran2.csv diff --git a/vignettes/Data/mdata.csv b/vignettes/articles/Data/mdata.csv similarity index 100% rename from vignettes/Data/mdata.csv rename to vignettes/articles/Data/mdata.csv diff --git a/vignettes/Data/reserved.csv b/vignettes/articles/Data/reserved.csv similarity index 100% rename from vignettes/Data/reserved.csv rename to vignettes/articles/Data/reserved.csv diff --git a/vignettes/Images/Slide1.png b/vignettes/articles/Images/Slide1.png similarity index 100% rename from vignettes/Images/Slide1.png rename to vignettes/articles/Images/Slide1.png diff --git a/vignettes/Images/Slide2.png b/vignettes/articles/Images/Slide2.png similarity index 100% rename from vignettes/Images/Slide2.png rename to vignettes/articles/Images/Slide2.png diff --git a/vignettes/Images/downloadPNG.png b/vignettes/articles/Images/downloadPNG.png similarity index 100% rename from vignettes/Images/downloadPNG.png rename to vignettes/articles/Images/downloadPNG.png diff --git a/vignettes/Images/export.png b/vignettes/articles/Images/export.png similarity index 100% rename from vignettes/Images/export.png rename to vignettes/articles/Images/export.png diff --git a/vignettes/Images/installPkg.png b/vignettes/articles/Images/installPkg.png similarity index 100% rename from vignettes/Images/installPkg.png rename to vignettes/articles/Images/installPkg.png diff --git a/vignettes/Images/model_builder/covariates.png b/vignettes/articles/Images/model_builder/covariates.png similarity index 100% rename from vignettes/Images/model_builder/covariates.png rename to vignettes/articles/Images/model_builder/covariates.png diff --git a/vignettes/Images/model_builder/eqn.png b/vignettes/articles/Images/model_builder/eqn.png similarity index 100% rename from vignettes/Images/model_builder/eqn.png rename to vignettes/articles/Images/model_builder/eqn.png diff --git a/vignettes/Images/model_builder/front.png b/vignettes/articles/Images/model_builder/front.png similarity index 100% rename from vignettes/Images/model_builder/front.png rename to vignettes/articles/Images/model_builder/front.png diff --git a/vignettes/Images/model_builder/lag.png b/vignettes/articles/Images/model_builder/lag.png similarity index 100% rename from vignettes/Images/model_builder/lag.png rename to vignettes/articles/Images/model_builder/lag.png diff --git a/vignettes/Images/model_builder/output.png b/vignettes/articles/Images/model_builder/output.png similarity index 100% rename from vignettes/Images/model_builder/output.png rename to vignettes/articles/Images/model_builder/output.png diff --git a/vignettes/Images/model_builder/output2.png b/vignettes/articles/Images/model_builder/output2.png similarity index 100% rename from vignettes/Images/model_builder/output2.png rename to vignettes/articles/Images/model_builder/output2.png diff --git a/vignettes/Images/model_builder/primary.png b/vignettes/articles/Images/model_builder/primary.png similarity index 100% rename from vignettes/Images/model_builder/primary.png rename to vignettes/articles/Images/model_builder/primary.png diff --git a/vignettes/Images/model_builder/secondary.png b/vignettes/articles/Images/model_builder/secondary.png similarity index 100% rename from vignettes/Images/model_builder/secondary.png rename to vignettes/articles/Images/model_builder/secondary.png diff --git a/vignettes/Images/multi-bv40.png b/vignettes/articles/Images/multi-bv40.png similarity index 100% rename from vignettes/Images/multi-bv40.png rename to vignettes/articles/Images/multi-bv40.png diff --git a/vignettes/Images/plotBrowser.png b/vignettes/articles/Images/plotBrowser.png similarity index 100% rename from vignettes/Images/plotBrowser.png rename to vignettes/articles/Images/plotBrowser.png diff --git a/vignettes/Images/pta1.png b/vignettes/articles/Images/pta1.png similarity index 100% rename from vignettes/Images/pta1.png rename to vignettes/articles/Images/pta1.png diff --git a/vignettes/Images/pta2.png b/vignettes/articles/Images/pta2.png similarity index 100% rename from vignettes/Images/pta2.png rename to vignettes/articles/Images/pta2.png diff --git a/vignettes/Images/schemaTop.png b/vignettes/articles/Images/schemaTop.png similarity index 100% rename from vignettes/Images/schemaTop.png rename to vignettes/articles/Images/schemaTop.png diff --git a/vignettes/Images/unibv40.png b/vignettes/articles/Images/unibv40.png similarity index 100% rename from vignettes/Images/unibv40.png rename to vignettes/articles/Images/unibv40.png diff --git a/vignettes/data.Rmd b/vignettes/articles/data.Rmd similarity index 100% rename from vignettes/data.Rmd rename to vignettes/articles/data.Rmd diff --git a/vignettes/intro.Rmd b/vignettes/articles/intro.Rmd similarity index 100% rename from vignettes/intro.Rmd rename to vignettes/articles/intro.Rmd diff --git a/vignettes/models.Rmd b/vignettes/articles/models.Rmd similarity index 100% rename from vignettes/models.Rmd rename to vignettes/articles/models.Rmd diff --git a/vignettes/objects.Rmd b/vignettes/articles/objects.Rmd similarity index 100% rename from vignettes/objects.Rmd rename to vignettes/articles/objects.Rmd diff --git a/vignettes/overview.Rmd b/vignettes/articles/overview.Rmd similarity index 100% rename from vignettes/overview.Rmd rename to vignettes/articles/overview.Rmd diff --git a/vignettes/plotly.Rmd b/vignettes/articles/plotly.Rmd similarity index 100% rename from vignettes/plotly.Rmd rename to vignettes/articles/plotly.Rmd diff --git a/vignettes/pmetrics.Rmd b/vignettes/articles/pmetrics.Rmd similarity index 100% rename from vignettes/pmetrics.Rmd rename to vignettes/articles/pmetrics.Rmd diff --git a/vignettes/pta.Rmd b/vignettes/articles/pta.Rmd similarity index 100% rename from vignettes/pta.Rmd rename to vignettes/articles/pta.Rmd diff --git a/vignettes/running.Rmd b/vignettes/articles/running.Rmd similarity index 100% rename from vignettes/running.Rmd rename to vignettes/articles/running.Rmd diff --git a/vignettes/simulation.Rmd b/vignettes/articles/simulation.Rmd similarity index 100% rename from vignettes/simulation.Rmd rename to vignettes/articles/simulation.Rmd diff --git a/vignettes/style.css b/vignettes/articles/style.css similarity index 100% rename from vignettes/style.css rename to vignettes/articles/style.css diff --git a/vignettes/workflow.Rmd b/vignettes/articles/workflow.Rmd similarity index 100% rename from vignettes/workflow.Rmd rename to vignettes/articles/workflow.Rmd