saveProject: Save project data to a backing file.

View source: R/manageProjectData.R

saveProjectR Documentation

Save project data to a backing file.

Description

Write a project data structure to its data file. This should rarely be necessary, since most of the functions that modify a project file have an option to write the data back to the file. Mostly it is intended for internal use, but it's exported in case it's useful to someone for some reason.

Usage

saveProject(prjdata, file = NULL, compress = NULL)

Arguments

prjdata

Project data object.

file

Filename to save to. If NULL, use the file the project was loaded from.

compress

The compress param to be passed on to base::save. Given we call this method indirectly from so many methods if not explicitly provided then we check the global options options("rgcam.saved_compressed") and if that is not set we fall back to the default behavior which continues to be "xz".

Details

The project data structure includes the name of its backing file, which is why you can call this function with no file argument. When you save with an explicit file name, the function returns a version of the data structure with an updated file attribute. If you want the data structure in the calling frame to have its backing file updated, you have to assign this return value back to the original object; otherwise you will write a copy of the data set, but your working copy will continue to be backed by the original file.

Note: when the project is written to disk the file attribute is stripped first so users can safely move, rename, share a project file without any problems.

For example:

> prj <- loadProject(file1.dat)
> saveProject(prj, 'file2.dat')       # prj is still backed by 'file1.dat'
### ... modify prj ...
> saveProject(prj)                    # new data written to 'file1.dat'
> prj <- saveProject(prj,'file3.dat') # prj now backed by 'file3.dat'
### ... modify prj again ...
> saveProject(prj)                    # newest data written to 'file3.dat'

JGCRI/rgcam documentation built on July 2, 2022, 10:20 a.m.