Passer au contenu

This R6 class is designed to manage experimental data, including observation sheets, metadata, and traceability logs. It provides methods to import, merge, and export data from Excel files while tracking operations for reproducibility.

Public fields

name

name of the user_data object, by default "user_data".

excel_data_trial

Path to the current Excel file used for import/export operations.

obs_data

A named list of data.frames, each corresponding to a sheet or file containing observation data.

metadata

A list storing metadata tables, such as "placette" and "modalite".

plot_tnt_association

A list storing association tables between plot and TNT.

prepared_data

A list storing prepared_data tables ready for stats analysis as produced by the function prepare_data()

stats

A list storing stats results as results of the function stats_tests()

traceability

A data.frame storing a log of all operations performed on the data (import, export, update, etc.).

Methods


Method new()

Initializes a new user_data object. If no Excel file is provided, a default template is used.

Usage

user_data$new(trial_file = NULL, name = NULL)

Arguments

trial_file

Optional. Path to the Excel file to load. If NULL, a default template is used.

name

optional. A string to name the new user_data object

Returns

A new instance of the UserData class.


Method add_metadata()

Adds or updates a metadata element in the metadata slot.

Usage

user_data$add_metadata(name, value)

Arguments

name

A single character string specifying the name of the element to add.

value

The object to add (e.g., a data.frame, list, or other metadata).

Returns

None. Modifies the metadata list in-place.


Method add_obs()

Adds a new observation dataset to obs_data or replaces an existing one. Automatically logs the operation and adds provenance columns.

Usage

user_data$add_obs(name, df, source_file = NULL, overwrite = FALSE)

Arguments

name

Name of the observation source.

df

A data.frame containing the observation data.

source_file

the source file path

overwrite

Logical. If TRUE, replaces an existing entry with the same name.

Returns

None. The object is modified in place.


Method show_obs_data()

Displays the first few rows of each observation dataset stored in obs_data.

Usage

user_data$show_obs_data()

Returns

A list of data.frames (head of each dataset).


Method log_trace()

This function adds a new entry to the traceability log stored in the R6 object. It records the type of operation, the target file or sheet name(s), and the timestamp.

Usage

user_data$log_trace(operation, filename, description = "")

Arguments

operation

A character string describing the action performed (e.g. "import", "export", "update").

filename

A character string indicating the name(s) of the file or sheet involved in the operation.

description

A description of the operation to store in log

Returns

No return value. This function updates the internal traceability data frame.


Method clone()

The objects of this class are cloneable with this method.

Usage

user_data$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.