diff --git a/DESCRIPTION b/DESCRIPTION index b2d6e2a..bc88d11 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -46,7 +46,6 @@ Imports: sp, sf, stats, - stringr, tibble, tidyr, tidyselect @@ -56,7 +55,8 @@ Suggests: testthat, ggplot2, htmlwidgets, - drat + drat, + yaml LazyData: true Encoding: UTF-8 VignetteBuilder: knitr diff --git a/NAMESPACE b/NAMESPACE index f12608e..f5db3c5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -105,8 +105,7 @@ importFrom(readr,read_delim_chunked) importFrom(rgbif,name_backbone) importFrom(rlang,"!!") importFrom(rlang,.data) -importFrom(sessioninfo,package_info) -importFrom(sessioninfo,platform_info) +importFrom(sessioninfo,session_info) importFrom(sf,st_as_sf) importFrom(sf,st_coordinates) importFrom(sf,st_crs) @@ -121,13 +120,10 @@ 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 index 0d63c10..5560403 100644 --- a/R/write_sessioninfo.R +++ b/R/write_sessioninfo.R @@ -10,62 +10,33 @@ #' \itemize{ #' \item{essential platform info: version, os, system, ctype} #' \item{essential info on loaded packages: package, loadedversion, date, -#' source if different from CRAN.} +#' source.} #' } #' #' @param file A file path or a \code{\link[base]{connection}}. +#' @inheritParams sessioninfo::session_info #' -#' @importFrom sessioninfo -#' platform_info -#' package_info -#' @importFrom stringr -#' str_detect -#' @importFrom utils -#' write.table -#' capture.output -#' @importFrom rlang -#' .data -#' @importFrom dplyr -#' mutate -#' select +#' @importFrom sessioninfo session_info #' #' @export #' #' @examples #' \dontrun{ -#' write_sessioninfo(file = "sessioninfo.txt") +#' write_sessioninfo(file = "sessioninfo.yml") #' } -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) - +write_sessioninfo <- function(file, pkgs = NULL, include_base = FALSE) { + si <- session_info() + si[["platform"]] <- si[["platform"]][c("version", "os", "system", "ctype")] + relevant <- c("loadedversion", "date", "source") + si[["packages"]] <- apply( + si[["packages"]], + 1, + function(x) { + as.list(x[relevant]) + } + ) + if (!requireNamespace("yaml", quietly = TRUE)) { + stop("please install the 'yaml' package first") + } + yaml::write_yaml(si, file) } diff --git a/man/write_sessioninfo.Rd b/man/write_sessioninfo.Rd index b2ca785..58fe8e0 100644 --- a/man/write_sessioninfo.Rd +++ b/man/write_sessioninfo.Rd @@ -4,10 +4,17 @@ \alias{write_sessioninfo} \title{Write essential session info to a file or connection} \usage{ -write_sessioninfo(file) +write_sessioninfo(file, pkgs = NULL, include_base = FALSE) } \arguments{ \item{file}{A file path or a \code{\link[base]{connection}}.} + +\item{pkgs}{Either a vector of package names or NULL. If \code{NULL}, +displays all loaded packages. If a character vector, also, includes +all dependencies of the package.} + +\item{include_base}{Include base packages in summary? By default this is +false since base packages should always match the R version.} } \description{ Writes essentials of @@ -21,11 +28,11 @@ 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.} +source.} } } \examples{ \dontrun{ -write_sessioninfo(file = "sessioninfo.txt") +write_sessioninfo(file = "./sessioninfo.yml") } }