# NOT RUN {
#############################################################################
# Setup
# Any existing "projects" folder is left totally untouched,
# and the user's home directory and .Renviron file are also left untouched.
old_home <- Sys.getenv("HOME")
old_ppath <- Sys.getenv("PROJECTS_FOLDER_PATH")
temp_dir <- tempfile("dir")
dir.create(temp_dir)
Sys.setenv(HOME = temp_dir)
Sys.unsetenv("PROJECTS_FOLDER_PATH")
#############################################################################
# Creating the projects folder
setup_projects(path = temp_dir)
# Viewing the projects folder path:
path1 <- projects_folder()
# Viewing the contents of the projects folder:
list.files(path1, full.names = TRUE, recursive = TRUE, all.files = TRUE)
# Create an arbitrary subfolder in temp_dir:
subfolder_path <- file.path(temp_dir, "test")
dir.create(subfolder_path)
# Wrapped in if (interactive()) because it requires user input
if (interactive()) {
# The function won't let the user abandon the old projects folder...
setup_projects(path = subfolder_path)
# ...unless overwrite = TRUE
setup_projects(path = file.path(temp_dir, "test"), overwrite = TRUE)
# Even then, only the stored location of the projects folder is overwritten.
# The old projects folder still exists:
list.files(path1, full.names = TRUE, recursive = TRUE, all.files = TRUE)
# Giving the "projects" folder a different name:
setup_projects(path = temp_dir, folder_name = "studies", overwrite = TRUE)
}
#############################################################################
# Cleanup
# (or, the user can just restart R)
Sys.setenv(HOME = old_home, PROJECTS_FOLDER_PATH = old_ppath)
#############################################################################
# }
Run the code above in your browser using DataLab