nmr_meta_add {AlpsNMR} | R Documentation

## Add metadata to an nmr_dataset object

### Description

This is useful to add metadata to datasets that can be later used for plotting spectra or further analysis (PCA...).

### Usage

    nmr_meta_add(nmr_data, metadata, by = "NMRExperiment")

    nmr_meta_add_tidy_excel(nmr_data, excel_file)

### Arguments

`nmr_data` | an nmr_dataset_family object
`metadata` | A data frame with metadata to add
`by` | A column name of both the `nmr_data$metadata$external` and the metadata data.frame. If you want to merge two columns with different headers you can use a named character vector `c("NMRExperiment" = "ExperimentNMR")` where the left side is the column name of the `nmr_data$metadata$external` and the right side is the column name of the metadata data frame.
`excel_file` | Path to a tidy Excel file name. The Excel can consist of multiple sheets, that are added sequentially. The first column of the first sheet MUST be named as one of the metadata already present in the dataset, typically will be "NMRExperiment". The rest of the columns of the first sheet can be named at will. Similary, the first column of the second sheet must be named as one of the metadata already present in the dataset, typically "NMRExperiment" or any of the columns of the first sheet. The rest of the columns of the second sheet can be named at will. See the package vignette for an example.

### Value

The nmr_dataset_family object with the added metadata

### See Also

Other metadata functions: `Pipelines`, `nmr_meta_export()`, `nmr_meta_get_column()`, `nmr_meta_get()`

Other nmr_dataset functions: `[.nmr_dataset()`, `format.nmr_dataset()`, `load_and_save_functions`, `new_nmr_dataset()`, `nmr_interpolate_1D()`, `nmr_meta_export()`, `nmr_meta_get_column()`, `nmr_meta_get()`, `nmr_ppm_resolution()`, `nmr_read_samples()`, `print.nmr_dataset()`, `validate_nmr_dataset()`

Other nmr_dataset_1D functions: `[.nmr_dataset_1D()`, `computes_peak_width_ppm()`, `file_lister()`, `files_to_rDolphin()`, `format.nmr_dataset_1D()`, `is.nmr_dataset_1D()`, `load_and_save_functions`, `new_nmr_dataset_1D()`, `nmr_align_find_ref()`, `nmr_baseline_removal()`, `nmr_baseline_threshold()`, `nmr_exclude_region()`, `nmr_integrate_regions()`, `nmr_interpolate_1D()`, `nmr_meta_export()`, `nmr_meta_get_column()`, `nmr_meta_get()`, `nmr_normalize()`, `nmr_pca_build_model()`, `nmr_pca_outliers_filter()`, `nmr_pca_outliers_plot()`, `nmr_pca_outliers_robust()`, `nmr_pca_outliers()`, `nmr_ppm_resolution()`, `plot.nmr_dataset_1D()`, `plot_webgl()`, `print.nmr_dataset_1D()`, `rdCV_PLS_RF_ML()`, `rdCV_PLS_RF()`, `save_files_to_rDolphin()`, `to_ChemoSpec()`, `validate_nmr_dataset_peak_table()`, `validate_nmr_dataset()`

Other nmr_dataset_peak_table functions: `[.nmr_dataset_peak_table()`, `format.nmr_dataset_peak_table()`, `is.nmr_dataset_peak_table()`, `load_and_save_functions`, `new_nmr_dataset_peak_table()`, `nmr_meta_export()`, `nmr_meta_get_column()`, `nmr_meta_get()`, `print.nmr_dataset_peak_table()`, `validate_nmr_dataset_peak_table()`

### Examples

    # Load a demo dataset with four samples:
    dataset <- system.file("dataset-demo", package = "AlpsNMR")
    nmr_dataset <- nmr_read_samples_dir(dataset)

    # At first we just have the NMRExperiment column
    nmr_meta_get(nmr_dataset, groups = "external")
    # Get a table with NMRExperiment -> SubjectID
    dummy_metadata <- system.file("dataset-demo", "dummy_metadata.xlsx", package = "AlpsNMR")
    NMRExp_SubjID <- readxl::read_excel(dummy_metadata, sheet = 1)

    NMRExp_SubjID
    # We can link the SubjectID column of the first excel into the dataset
    nmr_dataset <- nmr_meta_add(nmr_dataset, NMRExp_SubjID, by = "NMRExperiment")
    nmr_meta_get(nmr_dataset, groups = "external")
    # The second excel can use the SubjectID:
    SubjID_Age <- readxl::read_excel(dummy_metadata, sheet = 2)
    SubjID_Age
    # Add the metadata by its SubjectID:
    nmr_dataset <- nmr_meta_add(nmr_dataset, SubjID_Age, by = "SubjectID")
    # The final loaded metadata:
    nmr_meta_get(nmr_dataset, groups = "external")

    # Read a tidy excel file:

    dataset <- system.file("dataset-demo", package = "AlpsNMR")
    nmr_dataset <- nmr_read_samples_dir(dataset)

    # At first we just have the NMRExperiment column
    nmr_meta_get(nmr_dataset, groups = "external")
    # Get a table with NMRExperiment -> SubjectID
    dummy_metadata <- system.file("dataset-demo", "dummy_metadata.xlsx", package = "AlpsNMR")

    nmr_dataset <-nmr_meta_add_tidy_excel(nmr_dataset, dummy_metadata)
    # Updated Metadata:
    nmr_meta_get(nmr_dataset, groups = "external")

[Package AlpsNMR version 3.2.3 Index]