Skip to content

Commit

Permalink
store session_info() as yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
ThierryO committed Sep 3, 2019
1 parent c7ebcb8 commit bef8fc8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 58 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ Imports:
sp,
sf,
stats,
stringr,
tibble,
tidyr,
tidyselect
Expand All @@ -56,7 +55,8 @@ Suggests:
testthat,
ggplot2,
htmlwidgets,
drat
drat,
yaml
LazyData: true
Encoding: UTF-8
VignetteBuilder: knitr
Expand Down
6 changes: 1 addition & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
67 changes: 19 additions & 48 deletions R/write_sessioninfo.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
13 changes: 10 additions & 3 deletions man/write_sessioninfo.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bef8fc8

Please sign in to comment.