R/freeze.R

Defines functions check_if_description get_version_and_pkgname freeze read_requirements_yaml

Documented in freeze

#' @importFrom purrr map
check_if_description = function(description) {

}
get_version_and_pkgname = function(description) {
  description[c("Version", "Package")]
}
#' @title Freeze the environment
#'
#' @description Function saves your environment to a csv file. It's inspired from
#' python "pip freeze" command and the only difference in fact is the output format.
#' However both are human-readable.
#' IMPORTANT NOTE: it takes into account your current session, so it is recommended
#' to run it whenever your main script ran.
#' @param filename filepath of the config file (default to "requirements.csv"). It is
#' recommended that you don't change it; both for convention reasons and the fact
#' that it's not the only function that takes it as default value
#'
#' @return normalized filepath (function is called for it's side effect)
#' @export freeze
#'
#' @examples
#' sessionInfo()
#' freeze()
#'
#' @importFrom utils sessionInfo
#' @importFrom utils write.csv
#' @importFrom magrittr %>%
#' @importFrom yaml as.yaml
#' @importFrom yaml read_yaml
#  ^ second import for tests only
freeze = function(filename = "requirements.yaml") {
  filepath = suppressWarnings(
    normalizePath(filename, winslash = "/")
  )
  message = paste("Packages saved to", filepath)
  save_reqs = function(l, filepath) {
    write(as.yaml(l), filepath)
  }
  # now run and save to your file!
  sessionInfo()$loadedOnly %>%
    map(~get_version_and_pkgname(.x)) %>%
    call_with_message(save_reqs, message)(filepath)
  return(filepath)
}
#' @importFrom jsonlite fromJSON
read_requirements_yaml = function() {
  
}
fcyprowski/microservicer documentation built on Nov. 4, 2019, 12:39 p.m.