diff --git a/DESCRIPTION b/DESCRIPTION index 2f64be9..b2d6e2a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: inborutils Title: Collection of Useful R Utilities -Version: 0.1.0.9061 +Version: 0.1.0.9062 Description: While working on research projects, typical small functionalities are useful across these projects. Instead of copy-pasting these functions in all indidivual project repositories/folders, this package collects these @@ -15,6 +15,7 @@ Authors@R: c( person("Thierry", "Onkelinx", role = "ctb", email = "thierry.onkelinx@inbo.be", comment = c(ORCID = "0000-0001-8804-4216")), person("Floris", "Vanderhaeghe", role = "ctb", email = "floris.vanderhaeghe@inbo.be", comment = c(ORCID = "0000-0002-6378-6229")), person("Pieter", "Verschelde", role = "ctb", email = "pieter.verschelde@inbo.be", comment = c(ORCID = "0000-0002-9199-421X")), + person("Els", "De Bie", role = "ctb", email = "els.debie@inbo.be", comment = c(ORCID = "0000-0001-7679-743X")), person("Research Institute for Nature and Forest (INBO)", role = "cph", email = "info@inbo.be") ) License: MIT + file LICENSE @@ -41,6 +42,7 @@ Imports: rgdal, rlang, RSQLite, + sessioninfo, sp, sf, stats, diff --git a/NAMESPACE b/NAMESPACE index aea436c..f12608e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -20,6 +20,7 @@ export(read_knmi_data) export(read_mow_data) export(reproject_coordinates) export(vif) +export(write_sessioninfo) exportMethods(dbDisconnect) importFrom(DBI,dbConnect) importFrom(DBI,dbDisconnect) @@ -104,6 +105,8 @@ importFrom(readr,read_delim_chunked) importFrom(rgbif,name_backbone) importFrom(rlang,"!!") importFrom(rlang,.data) +importFrom(sessioninfo,package_info) +importFrom(sessioninfo,platform_info) importFrom(sf,st_as_sf) importFrom(sf,st_coordinates) importFrom(sf,st_crs) @@ -118,10 +121,13 @@ importFrom(stats,cov2cor) importFrom(stats,lm) importFrom(stats,model.matrix) importFrom(stats,vcov) +importFrom(stringr,str_detect) importFrom(tibble,as_tibble) importFrom(tidyr,extract) importFrom(tidyr,separate) importFrom(tidyselect,ends_with) importFrom(tidyselect,enquo) importFrom(tidyselect,vars_pull) +importFrom(utils,capture.output) importFrom(utils,getFromNamespace) +importFrom(utils,write.table) diff --git a/R/write_sessioninfo.R b/R/write_sessioninfo.R new file mode 100644 index 0000000..0d63c10 --- /dev/null +++ b/R/write_sessioninfo.R @@ -0,0 +1,71 @@ +#' Write essential session info to a file or connection +#' +#' Writes essentials of +#' \code{\link[sessioninfo:session_info]{sessioninfo::session_info()}} +#' to a file or connection in order to +#' maintain versionable documentation of a workflow and aid +#' reproducibility. +#' +#' The following information is written: +#' \itemize{ +#' \item{essential platform info: version, os, system, ctype} +#' \item{essential info on loaded packages: package, loadedversion, date, +#' source if different from CRAN.} +#' } +#' +#' @param file A file path or a \code{\link[base]{connection}}. +#' +#' @importFrom sessioninfo +#' platform_info +#' package_info +#' @importFrom stringr +#' str_detect +#' @importFrom utils +#' write.table +#' capture.output +#' @importFrom rlang +#' .data +#' @importFrom dplyr +#' mutate +#' select +#' +#' @export +#' +#' @examples +#' \dontrun{ +#' write_sessioninfo(file = "sessioninfo.txt") +#' } +write_sessioninfo <- function(file) { + + platform_info()[c("version", + "os", + "system", + "ctype")] %>% + unlist %>% + as.matrix() %>% + write.table(file = file, + quote = FALSE, + col.names = FALSE, + sep = "\t") + + capture.output(cat("\n"), + file = file, + append = TRUE) + + package_info() %>% + as.data.frame %>% + mutate(non_cran = ifelse(str_detect(source, "CRAN"), + "", + source)) %>% + select(.data$package, + .data$loadedversion, + .data$date, + .data$non_cran) %>% + write.table(file = file, + quote = FALSE, + row.names = FALSE, + col.names = FALSE, + sep = " ", + append = TRUE) + +} diff --git a/_pkgdown.yml b/_pkgdown.yml index fdd9bf4..1e344fa 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -35,6 +35,10 @@ reference: contents: - df_factors_to_char - csv_to_sqlite + - title: "Enhancing transparency and reproducibility" + desc: "Functions to help in achieving transparency and reproducibility" + contents: + - write_sessioninfo - title: "Statistical modelling" desc: "Functions for handling statistical modelling tasks" contents: diff --git a/inborutils.Rproj b/inborutils.Rproj index dde2c3a..e4a061f 100644 --- a/inborutils.Rproj +++ b/inborutils.Rproj @@ -18,3 +18,5 @@ StripTrailingWhitespace: Yes BuildType: Package PackageUseDevtools: Yes PackageInstallArgs: --no-multiarch --with-keep.source +PackageCheckArgs: --as-cran +PackageRoxygenize: rd,collate,namespace diff --git a/man/inborutils-package.Rd b/man/inborutils-package.Rd index e75b4a9..7355549 100644 --- a/man/inborutils-package.Rd +++ b/man/inborutils-package.Rd @@ -37,6 +37,7 @@ Other contributors: \item Thierry Onkelinx \email{thierry.onkelinx@inbo.be} (0000-0001-8804-4216) [contributor] \item Floris Vanderhaeghe \email{floris.vanderhaeghe@inbo.be} (0000-0002-6378-6229) [contributor] \item Pieter Verschelde \email{pieter.verschelde@inbo.be} (0000-0002-9199-421X) [contributor] + \item Els De Bie \email{els.debie@inbo.be} (0000-0001-7679-743X) [contributor] \item Research Institute for Nature and Forest (INBO) \email{info@inbo.be} [copyright holder] } diff --git a/man/write_sessioninfo.Rd b/man/write_sessioninfo.Rd new file mode 100644 index 0000000..b2ca785 --- /dev/null +++ b/man/write_sessioninfo.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/write_sessioninfo.R +\name{write_sessioninfo} +\alias{write_sessioninfo} +\title{Write essential session info to a file or connection} +\usage{ +write_sessioninfo(file) +} +\arguments{ +\item{file}{A file path or a \code{\link[base]{connection}}.} +} +\description{ +Writes essentials of +\code{\link[sessioninfo:session_info]{sessioninfo::session_info()}} +to a file or connection in order to +maintain versionable documentation of a workflow and aid +reproducibility. +} +\details{ +The following information is written: +\itemize{ +\item{essential platform info: version, os, system, ctype} +\item{essential info on loaded packages: package, loadedversion, date, +source if different from CRAN.} +} +} +\examples{ +\dontrun{ +write_sessioninfo(file = "sessioninfo.txt") +} +}