R/temp_dir.R

#' Create and Delete Temporary Directories
#'
#'@description  Quickly create and delete a temporary directory with a *sort of* random filepath.
#'
#'@param tmpdir A directory to delete (and it's contents).
#'
#'@return A potential filepath, or the filepath that was created.
#'
#'@details For \code{terms_dates()}, you need to have an ODBC connection to the
#'EDS Database, named "Research". You also need the \code{DBI} package installed.
#'
#'@examples
#'
#'# Provides a filepath to use as the temp directory, but does not create the directory.
#'temp_dir()
#'
#'# Creates and returns the name of a temp directory.
#'tmpdir <- create_temp_dir()
#'
#'# Removes a directory and its contents. (Doesn't have to be a "temp" directory.
#'remove_temp_dir(tmpdir)
#'
#'@name tempdir
NULL

#'@name tempdir
#'@export
temp_dir <- function(){
  tmpdir <- paste0(getwd(),"/TEMPDIR",round(runif(1, 100, 1000), 0))
  return(tmpdir)
}

#'@name tempdir
#'@export
create_temp_dir <- function(){
  tmpdir <- temp_dir()
  dir.create(tmpdir)
  return(tmpdir)
}

#'@name tempdir
#'@export
remove_temp_dir <- function(tmpdir){
 unlink(tmpdir, recursive = TRUE)
}
christian-million/researchR documentation built on May 15, 2019, 12:45 p.m.