packrat/lib/x86_64-pc-linux-gnu/3.2.4/packrat/tests/test-cranlike-repositories.R

library(packrat)

(function() {

  # Disable R_TESTS within this scope (we don't want the R
  # subprocess to attempt to call startup.Rs)
  R_TESTS <- Sys.getenv("R_TESTS")
  Sys.unsetenv("R_TESTS")
  on.exit(Sys.setenv(R_TESTS = R_TESTS), add = TRUE)

  dir <- tempdir()
  owd <- setwd(dir)
  on.exit(setwd(owd), add = TRUE)

  # Save repos
  repos <- getOption("repos")
  on.exit(options(repos = repos), add = TRUE)

  # Create the local repo
  localCRAN <- file.path(dir, "sushi")
  packrat::repos_create(localCRAN)

  # Use only the 'sushi' repository
  options(repos = getOption("repos")["sushi"])

  # Create an example package.
  env <- new.env(parent = emptyenv())
  env$sashimi <- function() {}
  suppressMessages(
    utils::package.skeleton("sashimi", path = dir, environment = env)
  )

  # tidy up the broken package
  unlink(file.path(dir, "sashimi/man"), recursive = TRUE)

  # Try uploading the package from the directory itself (requires building)
  message("\nBuilding sashimi:\n")
  packrat::repos_upload(file.path(dir, "sashimi"), "sushi")

  # Try building and uploading a tarball
  system(paste("R --vanilla CMD build", file.path(dir, "sashimi")))
  tarball <- list.files(dir, pattern = "\\.tar\\.gz$")[[1]]
  packrat::repos_upload(file.path(dir, tarball), "sushi")

  # Try installing the package as normal
  tempLib <- file.path(dir, "library")
  dir.create(tempLib)
  install.packages("sashimi", lib = tempLib, type = "source")

  # avoid bogus warning from R CMD check
  eval(call("library", "sashimi", lib.loc = tempLib))
  detach("package:sashimi", unload = TRUE)

})()
maxbiostat/timeTreeSim documentation built on April 29, 2022, 5:11 p.m.