Project class to manage a project folder
PMProject.RdThis object can be used to manage a project folder. Use it to create analyses, freeze input files, etc.
Methods
Method validate()
Validate the project folder. Makes sure all expected files and folder exist and are valid. Also validates that all input files referenced in inputs.local.yaml exist.
Method parse_inputs()
Parse project.yaml and inputs.local.yaml into PMData objects. Reads the inputs definition file and the local paths file and combines them to create a list of PMData objects.
Returns
A list of PMData objects, one for each input defined in project.yaml that has a corresponding path in inputs.local.yaml
Examples
folder <- withr::local_tempdir()
pm <- pm_create_project(folder)
# After configuring project.yaml and inputs.local.yaml:
# data_list <- pm$parse_inputs()Method list_analyses()
Get all analysis names from the project. Returns the names of all valid analysis folders in the analyses directory.
Examples
folder <- withr::local_tempdir()
pm <- pm_create_project(folder)
invisible(pm$create_analysis("data_preparation"))
invisible(pm$create_analysis("modeling"))
pm$list_analyses()Method get_analysis()
Get an analysis object by name. Returns a PMAnalysis object for the specified analysis name.
Examples
folder <- withr::local_tempdir()
pm <- pm_create_project(folder)
invisible(pm$create_analysis("data_preparation"))
analysis <- pm$get_analysis("data_preparation")
analysisMethod get_artifact()
Get an artifact (output file) from an analysis by ID. Searches for files with the given ID (filename without extension) in analysis output directories.
Arguments
idCharacter. The artifact ID (filename without extension).
analysis_nameCharacter. Optional name of the analysis to search in. If not provided, searches all analyses and fails if not exactly one match is found.
Examples
folder <- withr::local_tempdir()
pm <- pm_create_project(folder)
analysis <- pm$create_analysis("data_preparation")
# Create a test output file
output <- analysis$get_output_path("results.csv", type = "table")
output$write(data.frame(x = 1:5))
# Get artifact from specific analysis
artifact <- pm$get_artifact("results", analysis_name = "data_preparation")
# Get artifact without specifying analysis (if unique across all analyses)
artifact <- pm$get_artifact("results")Method create_analysis()
Create a new analysis from template. Creates a new analysis folder with template structure including README.md, directories (code/, outputs/, intermediate/, logs/), and .gitignore file.
Examples
folder <- withr::local_tempdir()
pm <- pm_create_project(folder)
analysis <- pm$create_analysis("data_preparation")
analysisExamples
# Create a valid project to load
folder <- withr::local_tempdir()
invisible(pm_create_project(folder))
# Load the project
pm <- PMProject$new(folder)
pm
#> PMProject:
#> Path: /private/var/folders/0t/mvk3x4hx0pl31l5lcl11krcc0000gn/T/RtmpewLzrE/file102673885303a
#> Analyses: 0
## ------------------------------------------------
## Method `PMProject$parse_inputs`
## ------------------------------------------------
folder <- withr::local_tempdir()
pm <- pm_create_project(folder)
# After configuring project.yaml and inputs.local.yaml:
# data_list <- pm$parse_inputs()
## ------------------------------------------------
## Method `PMProject$list_analyses`
## ------------------------------------------------
folder <- withr::local_tempdir()
pm <- pm_create_project(folder)
invisible(pm$create_analysis("data_preparation"))
invisible(pm$create_analysis("modeling"))
pm$list_analyses()
#> [1] "data_preparation" "modeling"
## ------------------------------------------------
## Method `PMProject$get_analysis`
## ------------------------------------------------
folder <- withr::local_tempdir()
pm <- pm_create_project(folder)
invisible(pm$create_analysis("data_preparation"))
analysis <- pm$get_analysis("data_preparation")
analysis
#> PMAnalysis:
#> Name: data_preparation
#> Path: /private/var/folders/0t/mvk3x4hx0pl31l5lcl11krcc0000gn/T/RtmpewLzrE/file102674977d813/analyses/data_preparation
#> Project: /private/var/folders/0t/mvk3x4hx0pl31l5lcl11krcc0000gn/T/RtmpewLzrE/file102674977d813
## ------------------------------------------------
## Method `PMProject$get_artifact`
## ------------------------------------------------
folder <- withr::local_tempdir()
pm <- pm_create_project(folder)
analysis <- pm$create_analysis("data_preparation")
# Create a test output file
output <- analysis$get_output_path("results.csv", type = "table")
output$write(data.frame(x = 1:5))
# Get artifact from specific analysis
artifact <- pm$get_artifact("results", analysis_name = "data_preparation")
# Get artifact without specifying analysis (if unique across all analyses)
artifact <- pm$get_artifact("results")
## ------------------------------------------------
## Method `PMProject$create_analysis`
## ------------------------------------------------
folder <- withr::local_tempdir()
pm <- pm_create_project(folder)
analysis <- pm$create_analysis("data_preparation")
analysis
#> PMAnalysis:
#> Name: data_preparation
#> Path: /private/var/folders/0t/mvk3x4hx0pl31l5lcl11krcc0000gn/T/RtmpewLzrE/file102672a52a917/analyses/data_preparation
#> Project: /private/var/folders/0t/mvk3x4hx0pl31l5lcl11krcc0000gn/T/RtmpewLzrE/file102672a52a917