Title: | Organising Projects |
---|---|
Description: | A framework for organizing R projects with a standardized structure. Most analyses consist of three main components: code, results, and data, each with different requirements such as version control, sharing, and encryption. This package provides tools to set up and manage project directories, handle file paths consistently across operating systems, organize results using date-based structures, source code from specified directories, create and manage Quarto documents, and perform file operations safely. It ensures consistency across projects while accommodating different requirements for various types of content. |
Authors: | Richard Aubrey White [aut, cre]
|
Maintainer: | Richard Aubrey White <[email protected]> |
License: | MIT + file LICENSE |
Version: | 2024.6.5 |
Built: | 2025-03-19 14:17:40 UTC |
Source: | https://github.com/csids/org |
Create example project that uses quarto with results generated outside the .qmd file
create_project_quarto_external_results(home, results)
create_project_quarto_external_results(home, results)
home |
Location of the 'home' directory. |
results |
Location of the 'results' directory. |
Create example project that uses quarto with results generated from within the .qmd file
create_project_quarto_internal_results(home, results)
create_project_quarto_internal_results(home, results)
home |
Location of the 'home' directory. |
results |
Location of the 'results' directory. |
This function initializes the project by setting up folder locations and sourcing code files.
It saves folder locations in 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.
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", ... )
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", ... )
env |
The environment that the code will be sourced into (use |
home |
The folder containing 'Run.R' and 'R/' |
results |
A folder inside |
folders_to_be_sourced |
The names of folders that live inside |
source_folders_absolute |
If |
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 |
For more details see the help vignette:
vignette("intro", package = "org")
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.
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/") ) org::project$results_today org::project$raw
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/") ) org::project$results_today org::project$raw
Equivalent to the unix ls
command.
ls_files(path = ".", regexp = NULL)
ls_files(path = ".", regexp = NULL)
path |
A character vector of one or more paths. |
regexp |
A regular expression that is passed to |
filepaths and directory paths as a character vector
Move directory
move_directory(from, to, overwrite_to = FALSE)
move_directory(from, to, overwrite_to = FALSE)
from |
Filepath or directory path. |
to |
Filepath or directory path. |
overwrite_to |
Boolean. |
This function checks whether a specified package is installed in the current R environment. Optionally, it can install the package if it is not already installed.
package_installed(pkg, install_if_missing = FALSE)
package_installed(pkg, install_if_missing = FALSE)
pkg |
A character string specifying the name of the package to check. |
install_if_missing |
A logical value indicating whether to install the package if it is not installed. Default is |
A logical value: TRUE
if the package is installed (or successfully installed), FALSE
otherwise.
## Not run: org::package_installed("data.table") org::package_installed("ggplot2", install_if_missing = TRUE) ## End(Not run)
## Not run: org::package_installed("data.table") org::package_installed("ggplot2", install_if_missing = TRUE) ## End(Not run)
Construct path to a file or directory
path(...)
path(...)
... |
Character vectors that will be concatenated with "/" as a separator. |
This environment is used to store the locations of folders that are used in the project.
project
project
An environment containing the following elements:
The folder containing 'Run.R' and 'R/'
The folder inside results
with today's date, which is created by initialize_project
This function sets the results folder in the project environment. A folder with today's date will be created inside the results folder.
set_results(results, proj = org::project)
set_results(results, proj = org::project)
results |
A character vector specifying the results folder path(s). |
proj |
The project environment. Default is |
Nothing. Alters the proj
environment to include $results
and $results_today
.
This function writes text to a file, optionally including a header at the top of the file. The text and the header are converted from Linux newline format to Windows newline format before writing.
write_text( txt, file = "", header = "**THIS FILE IS CONSTANTLY OVERWRITTEN -- DO NOT MANUALLY EDIT**\r\n\r\n" )
write_text( txt, file = "", header = "**THIS FILE IS CONSTANTLY OVERWRITTEN -- DO NOT MANUALLY EDIT**\r\n\r\n" )
txt |
A character string of text to be written to the file. |
file |
A character string specifying the file path. Passed through to |
header |
An optional character string header to be inserted at the top of the text file. Default is |
No return value. The function is called for its side effect of writing to a file.
## Not run: org::write_text("Sample text", "output.txt") org::write_text("Another piece of text", "output.txt", "Custom Header\r\n\r\n") ## End(Not run)
## Not run: org::write_text("Sample text", "output.txt") org::write_text("Another piece of text", "output.txt", "Custom Header\r\n\r\n") ## End(Not run)