Skip to contents

org::initialize_project takes in 2+ arguments. It then saves folder locations in the return value (a new environment) and in org::project, which you will use in all of your subsequent code. An additional folder will be created on the user's file system (org::project$results_today) which corresponds to results/YYYY-MM-DD. The sourced folders are saved into org::project$env.

Usage

initialize_project(
  env = new.env(),
  home = NULL,
  results = NULL,
  folders_to_be_sourced = "R",
  source_folders_absolute = FALSE,
  encode_from = "UTF-8",
  encode_to = "latin1",
  ...
)

Arguments

env

The environment that the code will be sourced into (use .GlobalEnv to source code into the global environment)

home

The folder containing 'Run.R' and 'R/'

results

A folder inside results with today's date will be created and it will be accessible via org::project$results_today (this is where you will store all of your results)

folders_to_be_sourced

The names of folders that live inside home and all .r and .R files inside it will be sourced into the global environment.

source_folders_absolute

If TRUE then folders_to_be_sourced is an absolute folder reference. If FALSE then folders_to_be_sourced is relative and inside home.

encode_from

Folders current encoding (only used on Windows)

encode_to

Folders final encoding (only used on Windows)

...

Other folders that you would like to reference

Value

Returns an environment that contains:

  • Folder locations

  • An environment called env into which the code has been sourced into. There is also a side effect where org::project mirrors these values.

Details

For more details see the help vignette: vignette("intro", package = "org")

Examples

# \donttest{
org::initialize_project(
  home = paste0(tempdir(), "/git/analyses/2019/analysis3/"),
  results = paste0(tempdir(), "/dropbox/analyses_results/2019/analysis3/"),
  raw = paste0(tempdir(), "/data/analyses/2019/analysis3/")
)
#> You are NOT sourcing into .GlobalEnv. All functions will be sourced into an environment that is returned from this function.
#> Warning: Folder /tmp/Rtmpi57caS/git/analyses/2019/analysis3/R does not exist. Creating it now.
#> Sourcing all code inside /tmp/Rtmpi57caS/git/analyses/2019/analysis3/R into 
#> <environment: 0x56197842b6e0>
org::project$results_today
#> [1] "/tmp/Rtmpi57caS/dropbox/analyses_results/2019/analysis3//2022-07-20"
org::project$raw
#> [1] "/tmp/Rtmpi57caS/data/analyses/2019/analysis3"
# }