# Dual Inlet Examples

#### 2021-10-15

# Introduction

Isoreader supports several dual inlet IRMS data formats. This vignette shows some of the functionality for dual inlet data files. For additional information on operations more generally (caching, combining read files, data export, etc.), please consult the operations vignette. For details on downstream data processing and visualization, see the isoprocessor package.

    # load isoreader package
    library(isoreader)

# Reading files

Reading dual inlet files is as simple as passing one or multiple file or folder paths to the `iso_read_dual_inlet()` function. If folders are provided, any files that have a recognized continuous flow file extensions within those folders will be processed (e.g. all `.did` and `.caf`). Here we read several files that are bundled with the package as examples (and whose paths can be retrieved using the `iso_get_reader_example()` function).

    # all available examples
    iso_get_reader_examples() %>% knitr::kable()

filename | type | software | description
--- | --- | --- | ---
continuous_flow_example.cf | continuous flow | Isodat | Continuous Flow file format (older)
continuous_flow_example.dxf | continuous flow | Isodat | Continuous Flow file format (newer)
continuous_flow_example.iarc | continuous flow | ionOS | Continuous Flow data archive
dual_inlet_example.caf | dual inlet | Isodat | Dual Inlet file format (older)
dual_inlet_example.did | dual inlet | Isodat | Dual Inlet file format (newer)
dual_inlet_nu_example.txt | dual inlet | Nu | Dual Inlet file format
background_scan_example.scn | scan | Isodat | Scan file format
full_scan_example.scn | scan | Isodat | Scan file format
peak_shape_scan_example.scn | scan | Isodat | Scan file format
time_scan_example.scn | scan | Isodat | Scan file format

    # read dual inlet examples
    di_files <-
      iso_read_dual_inlet(
        iso_get_reader_example("dual_inlet_example.did"),
        iso_get_reader_example("dual_inlet_example.caf"),
        iso_get_reader_example("dual_inlet_nu_example.txt"),
        nu_masses = 49:44
      )
    #> Info: preparing to read 3 data files...
    #> Info: reading file 'dual_inlet_example.did' with '.did' reader...
    #> Info: reading file 'dual_inlet_example.caf' with '.caf' reader...
    #> Info: reading file 'dual_inlet_nu_example.txt' with '.txt' reader...
    #> Info: finished reading 3 files in 2.46 secs

# File summary

The `di_files` variable now contains a set of isoreader objects, one for each file. Take a look at what information was retrieved from the files using the `iso_get_data_summary()` function.

    di_files %>% iso_get_data_summary() %>% knitr::kable()
    #> Info: aggregating data summary from 3 data file(s)

file_id | raw_data | file_info | method_info | vendor_data_table | file_path
--- | --- | --- | --- | --- | ---
dual_inlet_example.did | 7 cycles, 6 ions (44,45,46,47,48,49) | 16 entries | standards, resistors | 7 rows, 8 columns | dual_inlet_example.did
dual_inlet_example.caf | 8 cycles, 6 ions (44,45,46,47,48,49) | 22 entries | standards, resistors | 8 rows, 9 columns | dual_inlet_example.caf
dual_inlet_nu_example.txt | 82 cycles, 6 ions (44,45,46,47,48,49) | 9 entries | no method info | no vendor data table | dual_inlet_nu_example.txt

## Problems

In case there was any trouble with reading any of the files, the following functions provide an overview summary as well as details of all errors and warnings, respectively. The examples here contain no errors but if you run into any unexpected file read problems, please file a bug report in the isoreader issue tracker.

    di_files %>% iso_get_problems_summary() %>% knitr::kable()

file_id | error | warning
--- | --- | ---

    di_files %>% iso_get_problems() %>% knitr::kable()

file_id | type | func | details
--- | --- | --- | ---

# File Information

Detailed file information can be aggregated for all isofiles using the `iso_get_file_info()` function which supports the full select syntax of the dplyr package to specify which columns are of interest (by default, all file information is retrieved). Additionally, file information from different file formats can be renamed to the same column name for easy of downstream processing. The following provides a few examples for how this can be used (the names of the interesting info columns may vary between different file formats):

    # all file information
    di_files %>% iso_get_file_info(select = c(-file_root)) %>% knitr::kable()
    #> Info: aggregating file info from 3 data file(s), selecting info columns 'c(-file_root)'

file_id | file_path | file_subpath | file_datetime | file_size | Line | Peak Center | Pressadjust | Background | Identifier 1 | Identifier 2 | Analysis | Method | measurement_info | MS_integration_time.s | Reference Refill | Weight [mg] | Sample | Comment | Preparation | Pre Script | Post Script | Sample Name | Sample Weight | Method File Name
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
dual_inlet_example.did | dual_inlet_example.did | NA | 2014-10-27 05:23:54 | 134446 | 158 | 1 | 1 | 1 | CIT Carrara | 13 | 49077 | CO2_multiply_16V.met | Peak Center found at [61032] , Background: 8.87 mV,11.31 mV,12.98 mV,6.40 mV,1.90 mV,5.88 mV (old253), PressAdjust: L: 15972.5 R: 15971.6 ( Manual Adjustment ) | 26 | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA
dual_inlet_example.caf | dual_inlet_example.caf | NA | 2017-07-03 16:57:57 | 651704 | 1 | NA | NA | NA | 2H6 | CARBO IIIUvU_Clump.met | 16068 | CARBO IIIUvU_Clump.met | NA | 26 | NA | 113 | 9 | NA | NA | NA | NA | NA | NA | NA
dual_inlet_nu_example.txt | dual_inlet_nu_example.txt | NA | 2017-02-21 10:46:17 | 309491 | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | NA | ETH-01 | 3480 | C:Stable 4-20-8-20.rdf

    # select file information
    di_files %>%
      iso_get_file_info(
        select = c(
          # rename sample id columns from the different file types to a new ID column
          ID = `Identifier 1`, ID = `Sample Name`,
          # select columns without renaming
          Analysis, Method, `Peak Center`,
          # select the time stamp and rename it to `Date & Time`
          `Date & Time` = file_datetime,
          # rename weight columns from the different file types
          `Sample Weight`, `Sample Weight` = `Weight [mg]`
        ),
        # explicitly allow for file specific rename (for the new ID column)
        file_specific = TRUE
      ) %>% knitr::kable()
    #> Info: aggregating file info from 3 data file(s), selecting info columns 'c(ID = `Identifier 1`, ID = `Sample Name`, Analysis, Method, `Peak Center`, `Date & Time` = file_datetime, `Sample Weight`, `Sample Weight` = `Weight [mg]`)'

file_id | ID | Analysis | Method | Peak Center | Date & Time | Sample Weight
--- | --- | --- | --- | --- | --- | ---
dual_inlet_example.did | CIT Carrara | 49077 | CO2_multiply_16V.met | 1 | 2014-10-27 05:23:54 | NA
dual_inlet_example.caf | 2H6 | 16068 | CARBO IIIUvU_Clump.met | NA | 2017-07-03 16:57:57 | 113
dual_inlet_nu_example.txt | ETH-01 | NA | NA | NA | 2017-02-21 10:46:17 | 3480

## Select/Rename

Rather than retrieving specific file info columns using the above example of `iso_get_file_info(select = ...)`, these information can also be modified across an entire collection of isofiles using the `iso_select_file_info()` and `iso_rename_file_info()` functions. For example, the above example could be similarly achieved with the following use of `iso_select_file_info()`:

    # select + rename specific file info columns
    di_files2 <- di_files %>%
      iso_select_file_info(
        ID = `Identifier 1`, ID = `Sample Name`, Analysis, Method,
        `Peak Center`, `Date & Time` = file_datetime,
        `Sample Weight`, `Sample Weight` = `Weight [mg]`,
        file_specific = TRUE
      )
    #> Info: selecting/renaming the following file info:
    #>  - for 1 file(s): 'file_id', 'Identifier 1'->'ID', 'Analysis', 'Method', 'Peak Center', 'file_datetime'->'Date & Time'
    #>  - for 1 file(s): 'file_id', 'Identifier 1'->'ID', 'Analysis', 'Method', 'Peak Center', 'file_datetime'->'Date & Time', 'Weight [mg]'->'Sample Weight'
    #>  - for 1 file(s): 'file_id', 'Sample Name'->'ID', 'file_datetime'->'Date & Time', 'Sample Weight'

    # fetch all file info
    di_files2 %>% iso_get_file_info() %>% knitr::kable()
    #> Info: aggregating file info from 3 data file(s)

file_id | ID | Analysis | Method | Peak Center | Date & Time | Sample Weight
--- | --- | --- | --- | --- | --- | ---
dual_inlet_example.did | CIT Carrara | 49077 | CO2_multiply_16V.met | 1 | 2014-10-27 05:23:54 | NA
dual_inlet_example.caf | 2H6 | 16068 | CARBO IIIUvU_Clump.met | NA | 2017-07-03 16:57:57 | 113
dual_inlet_nu_example.txt | ETH-01 | NA | NA | NA | 2017-02-21 10:46:17 | 3480

## Filter

Any collection of isofiles can also be filtered based on the available file information using the function `iso_filter_files`. This function can operate on any column available in the file information and supports full dplyr syntax.

    # find files that have 'CIT' in the new ID field
    di_files2 %>% iso_filter_files(grepl("CIT", ID)) %>%
      iso_get_file_info() %>%
      knitr::kable()
    #> Info: applying file filter, keeping 1 of 3 files
    #> Info: aggregating file info from 1 data file(s)

file_id | ID | Analysis | Method | Peak Center | Date & Time
--- | --- | --- | --- | --- | ---
dual_inlet_example.did | CIT Carrara | 49077 | CO2_multiply_16V.met | 1 | 2014-10-27 05:23:54

    # find files that were run in 2017
    di_files2 %>%
      iso_filter_files(`Date & Time` > "2017-01-01" & `Date & Time` < "2018-01-01") %>%
      iso_get_file_info() %>%
      knitr::kable()
    #> Info: applying file filter, keeping 2 of 3 files
    #> Info: aggregating file info from 2 data file(s)

file_id | ID | Analysis | Method | Peak Center | Date & Time | Sample Weight
--- | --- | --- | --- | --- | --- | ---
dual_inlet_example.caf | 2H6 | 16068 | CARBO IIIUvU_Clump.met | NA | 2017-07-03 16:57:57 | 113
dual_inlet_nu_example.txt | ETH-01 | NA | NA | NA | 2017-02-21 10:46:17 | 3480

## Mutate

The file information in any collection of isofiles can also be mutated using the function `iso_mutate_file_info`. This function can introduce new columns and operate on/overwrite any existing columns available in the file information (even if it does not exist in all files) and supports full dplyr syntax. It can also be used in conjunction with `iso_with_unit` to generate values with implicit units.

    di_files3 <- di_files2 %>%
      iso_mutate_file_info(
        # update existing column
        ID = paste("ID:", ID),
        # introduce new column
        `Run in 2017?` = `Date & Time` > "2017-01-01" & `Date & Time` < "2018-01-01",
        # parse weight as a number and turn into a column with units
        `Sample Weight` = `Sample Weight` %>% parse_number() %>% iso_with_units("mg")
      )
    #> Info: mutating file info for 3 data file(s)

    di_files3 %>%
      iso_get_file_info() %>%
      iso_make_units_explicit() %>%
      knitr::kable()
    #> Info: aggregating file info from 3 data file(s)

file_id | ID | Analysis | Method | Peak Center | Date & Time | Sample Weight [mg] | Run in 2017?
--- | --- | --- | --- | --- | --- | --- | ---
dual_inlet_example.did | ID: CIT Carrara | 49077 | CO2_multiply_16V.met | 1 | 2014-10-27 05:23:54 | NA | FALSE
dual_inlet_example.caf | ID: 2H6 | 16068 | CARBO IIIUvU_Clump.met | NA | 2017-07-03 16:57:57 | 113 | TRUE
dual_inlet_nu_example.txt | ID: ETH-01 | NA | NA | NA | 2017-02-21 10:46:17 | 3480 | TRUE

## Add

Additionally, a wide range of new file information can be added in the form of a data frame with any number of columns (usually read from a comma-separated-value/csv file or an Excel/xlsx file) using the function `iso_add_file_info` and specifying which existing file information should be used to merge in the new information. It is similar to dplyr’s left_join but with additional safety checks and the possibility to join the new information sequentially as illustrated below.

    # this kind of information data frame is frequently read in from a csv or xlsx file
    new_info <-
      dplyr::bind_rows(
        # new information based on new vs. old samples
        dplyr::tribble(
          ~Analysis, ~`Run in 2017?`,  ~process,  ~info,
           NA,       TRUE,              "yes",     "2017 runs",
           NA,       FALSE,             "yes",     "other runs"
        ),
        # new information for a single specific file
        dplyr::tribble(
          ~Analysis, ~process,  ~note,
           "16068",   "no",      "did not inject properly"
        )
      )
    new_info %>% knitr::kable()

Analysis | Run in 2017? | process | info | note
--- | --- | --- | --- | ---
NA | TRUE | yes | 2017 runs | NA
NA | FALSE | yes | other runs | NA
16068 | NA | no | NA | did not inject properly

    # adding it to the isofiles
    di_files3 %>%
      iso_add_file_info(new_info, by1 = "Run in 2017?", by2 = "Analysis") %>%
      iso_get_file_info(select = !!names(new_info)) %>%
      knitr::kable()
    #> Info: adding new file information ('process', 'info', 'note') to 3 data file(s), joining by 'Run in 2017?' then 'Analysis'...
    #>  - 'Run in 2017?' join: 2/2 new info rows matched 3/3 data files - 1 of these was/were also matched by subsequent joins which took precedence
    #>  - 'Analysis' join: 1/1 new info rows matched 1/3 data files
    #> Info: aggregating file info from 3 data file(s), selecting info columns 'Analysis', 'Run in 2017?', 'process', 'info', 'note'

file_id | Analysis | Run in 2017? | process | info | note
--- | --- | --- | --- | --- | ---
dual_inlet_example.did | 49077 | FALSE | yes | other runs | NA
dual_inlet_example.caf | 16068 | TRUE | no | NA | did not inject properly
dual_inlet_nu_example.txt | NA | TRUE | yes | 2017 runs | NA

## Parse

Most file information is initially read as text to avoid cumbersome specifications during the read process and compatibility issues between different IRMS file formats. However, many file info columns are not easily processed as text. The isoreader package therefore provides several parsing and data extraction functions to facilitate processing the text-based data (some via functionality implemented by the readr package). See code block below for examples. For a complete overview, see the `?extract_data` and `?iso_parse_file_info` documentation.

    # use parsing and extraction in iso_mutate_file_info
    di_files2 %>%
      iso_mutate_file_info(
        # change type of Peak Center to logical
        `Peak Center` = parse_logical(`Peak Center`),
        # retrieve first word of Method column
        Method_1st = extract_word(Method),
        # retrieve second word of Method column
        Method_2nd = extract_word(Method, 2),
        # retrieve file extension from the file_id using regular expression
        extension = extract_substring(file_id, "\\.(\\w+)$", capture_bracket = 1)
      ) %>%
      iso_get_file_info(select = c(extension, `Peak Center`, matches("Method"))) %>%
      knitr::kable()
    #> Info: mutating file info for 3 data file(s)
    #> Info: aggregating file info from 3 data file(s), selecting info columns 'c(extension, `Peak Center`, matches("Method"))'

file_id | extension | Peak Center | Method | Method_1st | Method_2nd
--- | --- | --- | --- | --- | ---
dual_inlet_example.did | did | TRUE | CO2_multiply_16V.met | CO2 | multiply
dual_inlet_example.caf | caf | NA | CARBO IIIUvU_Clump.met | CARBO | IIIUvU
dual_inlet_nu_example.txt | txt | NA | NA | NA | NA

    # use parsing in iso_filter_file_info
    di_files2 %>%
      iso_filter_files(parse_integer(Analysis) > 1500) %>%
      iso_get_file_info() %>%
      knitr::kable()
    #> Info: applying file filter, keeping 2 of 3 files
    #> Info: aggregating file info from 2 data file(s)

file_id | ID | Analysis | Method | Peak Center | Date & Time | Sample Weight
--- | --- | --- | --- | --- | --- | ---
dual_inlet_example.did | CIT Carrara | 49077 | CO2_multiply_16V.met | 1 | 2014-10-27 05:23:54 | NA
dual_inlet_example.caf | 2H6 | 16068 | CARBO IIIUvU_Clump.met | NA | 2017-07-03 16:57:57 | 113

    # use iso_parse_file_info for simplified parsing of column data types
    di_files2 %>%
      iso_parse_file_info(
        integer = Analysis,
        number = `Sample Weight`,
        logical = `Peak Center`
      ) %>%
      iso_get_file_info() %>%
      knitr::kable()
    #> Info: parsing 3 file info columns for 3 data file(s):
    #>  - to integer: 'Analysis'
    #>  - to logical: 'Peak Center'
    #>  - to number: 'Sample Weight'
    #> Info: aggregating file info from 3 data file(s)

file_id | ID | Analysis | Method | Peak Center | Date & Time | Sample Weight
--- | --- | --- | --- | --- | --- | ---
dual_inlet_example.did | CIT Carrara | 49077 | CO2_multiply_16V.met | TRUE | 2014-10-27 05:23:54 | NA
dual_inlet_example.caf | 2H6 | 16068 | CARBO IIIUvU_Clump.met | NA | 2017-07-03 16:57:57 | 113
dual_inlet_nu_example.txt | ETH-01 | NA | NA | NA | 2017-02-21 10:46:17 | 3480

# Resistors

Additionally, some IRMS data files contain resistor information that are useful for downstream calculations (see e.g. section on signal conversion later in this vignette):

    di_files %>% iso_get_resistors() %>% knitr::kable()
    #> Info: aggregating resistors info from 3 data file(s)

file_id | cup | R.Ohm | mass
--- | --- | --- | ---
dual_inlet_example.did | 1 | 3.000000e+08 | 44
dual_inlet_example.did | 2 | 3.000000e+10 | 45
dual_inlet_example.did | 3 | 1.000000e+11 | 46
dual_inlet_example.did | 4 | 1.000000e+12 | 47
dual_inlet_example.did | 5 | 5.000000e+11 | 48
dual_inlet_example.did | 6 | 1.000000e+12 | 49
dual_inlet_example.caf | 1 | 2.970297e+08 | 44
dual_inlet_example.caf | 2 | 1.500000e+10 | 45
dual_inlet_example.caf | 3 | 5.000000e+10 | 46
dual_inlet_example.caf | 4 | 5.000000e+11 | 47
dual_inlet_example.caf | 5 | 9.900990e+09 | 48
dual_inlet_example.caf | 6 | 5.000000e+11 | 49

# Reference values

As well as isotopic reference values for the different gases:

    # reference delta values without ratio values
    di_files %>% iso_get_standards(file_id:reference) %>% knitr::kable()
    #> Info: aggregating standards info from 3 data file(s)

file_id | standard | gas | delta_name | delta_value | reference
--- | --- | --- | --- | --- | ---
dual_inlet_example.did | Caltech-1960C | CO2 | d 13C/12C | -3.56 | VPDB
dual_inlet_example.did | Caltech-1960C | CO2 | d 18O/16O | 25.01 | VSMOW
dual_inlet_example.caf | CO2clump tank | CO2 | d 13C/12C | -2.82 | VPDB
dual_inlet_example.caf | CO2clump tank | CO2 | d 18O/16O | -4.67 | VPDB
dual_inlet_example.caf | CO2clump tank | CO2 | d 47CO2/44CO2 | 0.00 | None
dual_inlet_example.caf | CO2clump tank | CO2 | d 48CO2/44CO2 | 0.00 | None
dual_inlet_example.caf | CO2clump tank | CO2 | d 49CO2/44CO2 | 0.00 | None

    # reference values with ratios
    di_files %>% iso_get_standards() %>% knitr::kable()
    #> Info: aggregating standards info from 3 data file(s)

file_id | standard | gas | delta_name | delta_value | reference | element | ratio_name | ratio_value
--- | --- | --- | --- | --- | --- | --- | --- | ---
dual_inlet_example.did | Caltech-1960C | CO2 | d 13C/12C | -3.56 | VPDB | C | R 13C/12C | 0.0111802
dual_inlet_example.did | Caltech-1960C | CO2 | d 13C/12C | -3.56 | VPDB | O | R 18O/16O | 0.0020672
dual_inlet_example.did | Caltech-1960C | CO2 | d 13C/12C | -3.56 | VPDB | O | R 17O/16O | 0.0003860
dual_inlet_example.did | Caltech-1960C | CO2 | d 18O/16O | 25.01 | VSMOW | H | R 2H/1H | 0.0001558
dual_inlet_example.did | Caltech-1960C | CO2 | d 18O/16O | 25.01 | VSMOW | O | R 17O/16O | 0.0003799
dual_inlet_example.did | Caltech-1960C | CO2 | d 18O/16O | 25.01 | VSMOW | O | R 18O/16O | 0.0020052
dual_inlet_example.caf | CO2clump tank | CO2 | d 13C/12C | -2.82 | VPDB | C | R 13C/12C | 0.0111802
dual_inlet_example.caf | CO2clump tank | CO2 | d 13C/12C | -2.82 | VPDB | O | R 18O/16O | 0.0020672
dual_inlet_example.caf | CO2clump tank | CO2 | d 13C/12C | -2.82 | VPDB | O | R 17O/16O | 0.0003860
dual_inlet_example.caf | CO2clump tank | CO2 | d 18O/16O | -4.67 | VPDB | C | R 13C/12C | 0.0111802
dual_inlet_example.caf | CO2clump tank | CO2 | d 18O/16O | -4.67 | VPDB | O | R 18O/16O | 0.0020672
dual_inlet_example.caf | CO2clump tank | CO2 | d 18O/16O | -4.67 | VPDB | O | R 17O/16O | 0.0003860
dual_inlet_example.caf | CO2clump tank | CO2 | d 47CO2/44CO2 | 0.00 | None | NA | NA | NA
dual_inlet_example.caf | CO2clump tank | CO2 | d 48CO2/44CO2 | 0.00 | None | NA | NA | NA
dual_inlet_example.caf | CO2clump tank | CO2 | d 49CO2/44CO2 | 0.00 | None | NA | NA | NA

# Raw Data

The raw data read from the IRMS files can be retrieved similarly using the `iso_get_raw_data()` function. Most data aggregation functions also allow for inclusion of file information using the `include_file_info` parameter, which functions identically to the `select` parameter of the `iso_get_file_info` function discussed earlier.

    # get raw data with default selections (all raw data, no additional file info)
    di_files %>% iso_get_raw_data() %>% head(n=10) %>% knitr::kable()
    #> Info: aggregating raw data from 3 data file(s)

file_id | type | cycle | v44.mV | v45.mV | v46.mV | v47.mV | v48.mV | v49.mV | block | i44.A | i45.A | i46.A | i47.A | i48.A | i49.A
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
dual_inlet_example.did | standard | 0 | 15946.42 | 19001.94 | 21960.62 | 2513.280 | 29.78742 | -181.2712 | NA | NA | NA | NA | NA | NA | NA
dual_inlet_example.did | standard | 1 | 15941.14 | 18995.66 | 21954.19 | 2512.345 | 29.80048 | -180.9752 | NA | NA | NA | NA | NA | NA | NA
dual_inlet_example.did | standard | 2 | 15933.54 | 18986.64 | 21943.58 | 2511.280 | 29.81818 | -180.7748 | NA | NA | NA | NA | NA | NA | NA
dual_inlet_example.did | standard | 3 | 15916.58 | 18966.34 | 21919.97 | 2508.497 | 29.78074 | -180.4583 | NA | NA | NA | NA | NA | NA | NA
dual_inlet_example.did | standard | 4 | 15901.62 | 18948.60 | 21899.17 | 2506.104 | 29.76304 | -180.2311 | NA | NA | NA | NA | NA | NA | NA
dual_inlet_example.did | standard | 5 | 15896.00 | 18941.97 | 21891.49 | 2505.600 | 29.75818 | -180.3095 | NA | NA | NA | NA | NA | NA | NA
dual_inlet_example.did | standard | 6 | 15884.63 | 18928.51 | 21876.19 | 2503.555 | 29.72923 | -180.2013 | NA | NA | NA | NA | NA | NA | NA
dual_inlet_example.did | standard | 7 | 15875.89 | 18918.12 | 21863.96 | 2502.444 | 29.69513 | -180.0340 | NA | NA | NA | NA | NA | NA | NA
dual_inlet_example.did | sample | 1 | 15955.18 | 19122.71 | 22237.99 | 2559.245 | 31.09436 | -181.2460 | NA | NA | NA | NA | NA | NA | NA
dual_inlet_example.did | sample | 2 | 15945.64 | 19111.16 | 22224.65 | 2557.857 | 31.09153 | -180.9976 | NA | NA | NA | NA | NA | NA | NA

    # get specific raw data and add some file information
    di_files %>%
      iso_get_raw_data(
        # select just time and the two ions
        select = c(type, cycle, v44.mV, v45.mV),
        # include the Analysis number fron the file info and rename it to 'run'
        include_file_info = c(run = Analysis)
      ) %>%
      # look at first few records only
      head(n=10) %>% knitr::kable()
    #> Info: aggregating raw data from 3 data file(s), selecting data columns 'c(type, cycle, v44.mV, v45.mV)', including file info 'c(run = Analysis)'

file_id | run | type | cycle | v44.mV | v45.mV
--- | --- | --- | --- | --- | ---
dual_inlet_example.did | 49077 | standard | 0 | 15946.42 | 19001.94
dual_inlet_example.did | 49077 | standard | 1 | 15941.14 | 18995.66
dual_inlet_example.did | 49077 | standard | 2 | 15933.54 | 18986.64
dual_inlet_example.did | 49077 | standard | 3 | 15916.58 | 18966.34
dual_inlet_example.did | 49077 | standard | 4 | 15901.62 | 18948.60
dual_inlet_example.did | 49077 | standard | 5 | 15896.00 | 18941.97
dual_inlet_example.did | 49077 | standard | 6 | 15884.63 | 18928.51
dual_inlet_example.did | 49077 | standard | 7 | 15875.89 | 18918.12
dual_inlet_example.did | 49077 | sample | 1 | 15955.18 | 19122.71
dual_inlet_example.did | 49077 | sample | 2 | 15945.64 | 19111.16

# Data Processing

The isoreader package is intended to make raw stable isotope data easily accessible. However, as with most analytical data, there is significant downstream processing required to turn these raw signal intensities into properly referenced isotopic measurement. This and similar functionality as well as data visualization is part of the isoprocessor package which takes isotopic data through the various corrections in a transparent, efficient and reproducible manner.

That said, most vendor software also performs some of these calculations and it can be useful to be able to compare new data reduction procedures against those implemented in the vendor software. For this purpose, isoreader retrieves vendor computed data tables whenever possible, as illustrated below.

## Vendor Data Table

As with most data retrieval functions, the `iso_get_vendor_data_table()` function also allows specific column selection (by default, all columns are selected) and easy addition of file information via the `include_file_info` parameter (by default, none is included).

    # entire vendor data table
    di_files %>% iso_get_vendor_data_table() %>% knitr::kable()
    #> Info: aggregating vendor data table from 3 data file(s)

file_id | cycle | d 45CO2/44CO2 | d 46CO2/44CO2 | d 13C/12C | d 18O/16O | d 17O/16O | AT% 13C/12C | AT% 18O/16O | d 47CO2/44CO2 | d 48CO2/44CO2 | d 49CO2/44CO2
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
dual_inlet_example.did | 1 | 3.3287770 | 37.330647 | 2.1929917 | 37.366456 | 6.202321 | 1.108056 | 0.2075809 | NA | NA | NA
dual_inlet_example.did | 2 | 3.3209553 | 37.311799 | 2.1852948 | 37.347605 | 6.192886 | 1.108048 | 0.2075772 | NA | NA | NA
dual_inlet_example.did | 3 | 3.3263384 | 37.317514 | 2.1908570 | 37.353314 | 6.195743 | 1.108054 | 0.2075783 | NA | NA | NA
dual_inlet_example.did | 4 | 3.3200304 | 37.317207 | 2.1841057 | 37.353021 | 6.195597 | 1.108047 | 0.2075782 | NA | NA | NA
dual_inlet_example.did | 5 | 3.3187408 | 37.329768 | 2.1822644 | 37.365600 | 6.201893 | 1.108045 | 0.2075808 | NA | NA | NA
dual_inlet_example.did | 6 | 3.3177548 | 37.322849 | 2.1814601 | 37.358675 | 6.198427 | 1.108044 | 0.2075794 | NA | NA | NA
dual_inlet_example.did | 7 | 3.3217518 | 37.318368 | 2.1859087 | 37.354180 | 6.196176 | 1.108049 | 0.2075785 | NA | NA | NA
dual_inlet_example.caf | 1 | 0.7000753 | 7.543204 | 0.4669423 | 7.550236 | 6.316518 | NA | NA | 15.65910 | 22.50135 | -58.12863
dual_inlet_example.caf | 2 | 0.6846506 | 7.518991 | 0.4512997 | 7.526031 | 6.304043 | NA | NA | 15.62094 | 22.59733 | -54.25812
dual_inlet_example.caf | 3 | 0.6827013 | 7.503826 | 0.4497784 | 7.510853 | 6.296221 | NA | NA | 15.56356 | 22.81077 | -52.21288
dual_inlet_example.caf | 4 | 0.6940694 | 7.513421 | 0.4616176 | 7.520432 | 6.301158 | NA | NA | 15.64200 | 23.18259 | -66.43734
dual_inlet_example.caf | 5 | 0.6748151 | 7.499821 | 0.4414657 | 7.506862 | 6.294164 | NA | NA | 15.56706 | 22.81533 | -67.80591
dual_inlet_example.caf | 6 | 0.6836593 | 7.492892 | 0.4512181 | 7.499905 | 6.290578 | NA | NA | 15.65654 | 23.33585 | -66.66771
dual_inlet_example.caf | 7 | 0.6960376 | 7.491672 | 0.4645483 | 7.498654 | 6.289934 | NA | NA | 15.56031 | 23.89354 | -42.32076
dual_inlet_example.caf | 8 | 0.6929899 | 7.499328 | 0.4609894 | 7.506326 | 6.293888 | NA | NA | 15.45959 | 24.43994 | -48.39355

    # get specific parts and add some file information
    di_files %>%
      iso_get_vendor_data_table(
        # select cycle and all carbon columns
        select = c(cycle, matches("C")),
        # include the Identifier 1 fron the file info and rename it to 'id'
        include_file_info = c(id = `Identifier 1`)
      ) %>% knitr::kable()
    #> Info: aggregating vendor data table from 3 data file(s), including file info 'c(id = `Identifier 1`)'

file_id | id | cycle | d 45CO2/44CO2 | d 46CO2/44CO2 | d 13C/12C | AT% 13C/12C | d 47CO2/44CO2 | d 48CO2/44CO2 | d 49CO2/44CO2
--- | --- | --- | --- | --- | --- | --- | --- | --- | ---
dual_inlet_example.did | CIT Carrara | 1 | 3.3287770 | 37.330647 | 2.1929917 | 1.108056 | NA | NA | NA
dual_inlet_example.did | CIT Carrara | 2 | 3.3209553 | 37.311799 | 2.1852948 | 1.108048 | NA | NA | NA
dual_inlet_example.did | CIT Carrara | 3 | 3.3263384 | 37.317514 | 2.1908570 | 1.108054 | NA | NA | NA
dual_inlet_example.did | CIT Carrara | 4 | 3.3200304 | 37.317207 | 2.1841057 | 1.108047 | NA | NA | NA
dual_inlet_example.did | CIT Carrara | 5 | 3.3187408 | 37.329768 | 2.1822644 | 1.108045 | NA | NA | NA
dual_inlet_example.did | CIT Carrara | 6 | 3.3177548 | 37.322849 | 2.1814601 | 1.108044 | NA | NA | NA
dual_inlet_example.did | CIT Carrara | 7 | 3.3217518 | 37.318368 | 2.1859087 | 1.108049 | NA | NA | NA
dual_inlet_example.caf | 2H6 | 1 | 0.7000753 | 7.543204 | 0.4669423 | NA | 15.65910 | 22.50135 | -58.12863
dual_inlet_example.caf | 2H6 | 2 | 0.6846506 | 7.518991 | 0.4512997 | NA | 15.62094 | 22.59733 | -54.25812
dual_inlet_example.caf | 2H6 | 3 | 0.6827013 | 7.503826 | 0.4497784 | NA | 15.56356 | 22.81077 | -52.21288
dual_inlet_example.caf | 2H6 | 4 | 0.6940694 | 7.513421 | 0.4616176 | NA | 15.64200 | 23.18259 | -66.43734
dual_inlet_example.caf | 2H6 | 5 | 0.6748151 | 7.499821 | 0.4414657 | NA | 15.56706 | 22.81533 | -67.80591
dual_inlet_example.caf | 2H6 | 6 | 0.6836593 | 7.492892 | 0.4512181 | NA | 15.65654 | 23.33585 | -66.66771
dual_inlet_example.caf | 2H6 | 7 | 0.6960376 | 7.491672 | 0.4645483 | NA | 15.56031 | 23.89354 | -42.32076
dual_inlet_example.caf | 2H6 | 8 | 0.6929899 | 7.499328 | 0.4609894 | NA | 15.45959 | 24.43994 | -48.39355

# For expert users: retrieving all data

For users familiar with the nested data frames from the tidyverse (particularly tidyr’s `nest` and `unnest`), there is an easy way to retrieve all data from the iso file objects in a single nested data frame:

    all_data <- di_files %>% iso_get_all_data()
    #> Info: aggregating all data from 3 data file(s)
    # not printed out because this data frame is very big

# Saving collections

Saving entire collections of isofiles for retrieval at a later point is easily done using the `iso_save` function which stores collections or individual isoreader file objects in the efficient R data storage format `.rds` (if not specified, the extension `.di.rds` will be automatically appended). These saved collections can be conveniently read back using the same `iso_read_dual_inlet` command used for raw data files.

    # export to R data archive
    di_files %>% iso_save("di_files_export.di.rds")
    #> Info: exporting data from 3 iso_files into R Data Storage 'di_files_export.di.rds'

    # read back the exported R data storage
    iso_read_dual_inlet("di_files_export.di.rds")
    #> Info: preparing to read 1 data files...
    #> Info: reading file 'di_files_export.di.rds' with '.di.rds' reader...
    #> Info: loaded 3 data files from R Data Storage
    #> Info: finished reading 1 files in 0.08 secs
    #> Data from 3 dual inlet iso files:
    #> # A tibble: 3 × 6
    #>   file_id     raw_data      file_info  method_info  vendor_data_tab… file_path
    #>   <chr>       <glue>        <chr>      <chr>        <chr>            <chr>
    #> 1 dual_inlet… 7 cycles, 6 … 16 entries standards, … 7 rows, 8 colum… dual_inlet…
    #> 2 dual_inlet… 8 cycles, 6 … 22 entries standards, … 8 rows, 9 colum… dual_inlet…
    #> 3 dual_inlet… 82 cycles, 6… 9 entries  no method i… no vendor data … dual_inlet…

# Data Export

At the moment, isoreader supports export of all data to Excel and the Feather file format (a Python/R cross-over format). Note that both export methods have similar syntax and append the appropriate file extension for each type of export file (`.di.xlsx` and `.di.feather`, respectively).

    # export to excel
    di_files %>% iso_export_to_excel("di_files_export")

    # data sheets available in the exported data file:
    readxl::excel_sheets("di_files_export.di.xlsx")

    # export to feather
    di_files %>% iso_export_to_feather("di_files_export")

    # exported feather files
    list.files(pattern = ".di.feather")