import_standard_record: Data import functions

View source: R/data_import.R

import_standard_recordR Documentation

Data import functions

Description

The bgfanalyzer package has three data import functions. Two are called internally by the helper functions from_standard_report or from_AMPTV2_report when creating a new BGF object. The third allows to import a BGF object, that was previously exported from R.

Usage

import_standard_record(
  ipath,
  dec = ".",
  sep = "\t",
  header = TRUE,
  mkFRTime = NULL,
  FRTime_col = NULL,
  units = NULL,
  ...
)

read_raw_AMPTSV2_report(path, sub = "\\\"")

import_BGF_object(path)

Arguments

ipath, path

a path pointing to an external file

dec

the character used in the file for decimal points.

sep

the field separator character. Values on each line of the file are separated by this character. If sep = "" (the default for read.table) the separator is ‘white space’, that is one or more spaces, tabs, newlines or carriage returns.

header

a logical value indicating whether the file contains the names of the variables as its first line. If missing, the value is determined from the file format: header is set to TRUE if and only if the first row contains one fewer field than the number of columns.

mkFRTime

NULL by default. Can be a character string representing a start date (%y-%m-%d %H:%M:%S) for the calculation of the fermentation time

FRTime_col

NULL by default. Can be a character string with the name, or an integer representing the position of the date column after the input file was read via read.table.

units

character string. Units in which the results are desired. Can be abbreviated.

...

Further arguments to be passed to read.table.

sub

a character, which will be eliminated from the read in text connection

Details

Two of the three data import functions, import_standard_record and read_raw_AMPTSV2_report are unlikely to be directly called by a package user. Instead, they are called by from_standard_record or from_AMPTSV2_report, respectively, when importing an external data file.

The first import function import_standard_record is more than a wrapper for read.table with the arguments dec=".", sep="\t" and header=TRUE pre-set. It furthermore allows to calculate a fermentation time directly when importing the data. To this end, mkFRTime must be a character string representing a date in the format %y-%m-%d %H:%M:%S, FRTime_col an integer specifying the position of the time stamp within the data, and units must be a character specifying the desired units of the calculated fermentation time.

In case of import_standard_record a data.frame is returned.

The function read_raw_AMPTSV2_report calls readLines and expects a relative path to a report_yyyy-mm-dd_HHMM.csv-file generated by the AMPTS II web interface (Login > Download report > Generate report > Download generated report as raw text file (CSV)). The function expects the original file generated by the AMPTS II, NOT a .CSV version previously opened and saved by other software as this will replace the original AMPTS II-generated formatting the downstream function is build on. The argument sub is used in a call to gsub, which is needed to eliminate an artifact character introduced by calling readLines. Upon artifact elimination the raw data is converted into a list of three:

ExpPara: A list. Information concerning the all reactors part of the AMPTS II experiment. Serves as template for ExpParam of a BGF

ExpSetup: A data.frame. Information on individual reactors being part of the AMPTS II experiment. All information collected here will be added to metaData of a BGF

ExpData: A data.frame. Biogas volumes and flow data of the AMPTS II experiment. This data will be moved to BioGasData of a BGF

This list is returned by read_raw_AMPTSV2_report.

The third data import function, import_BGF_object allows to import a BGF from either an .RDS-file or an .csv-file as produced by save_BGF. A detailed format description of the .csv-file this function can read can be found elsewhere. The function expects a path to a file as a single argument. It will check the ending of the file path. If it's '.csv', a BGF is rebuild based on the read in data. Else the function serves as a wrapper to readRDS. Consequently, a BGF is returned.

Value

Either a data.frame, a list or a BGF

Examples

# import biogas fermentation from a .tsv file
stRep <- import_standard_record(
      ipath = base::system.file("extdata","Fermentation_B.tsv",package ="bgfanalyzer"),
      header=TRUE,
      dec=".",
      sep="\t")

# calculate a fermentation time while importing the data
stRep_frt <- import_standard_record(
        ipath = base::system.file("extdata","Fermentation_B.tsv",package ="bgfanalyzer"),
        header=TRUE,
        dec=".",
        sep="\t",
        mkFRTime = "2026-01-29 23:00:00",
        FRTime_col = 2,
        units = "hours")


# create a list that can be used as a template to build a BGF
RawReport <- read_raw_AMPTSV2_report(
        path = base::system.file("extdata","AMPTSV2.csv",package ="bgfanalyzer"))



# import a BGF from a '.csv'-file
BGF_csv <- import_BGF_object(
      path = base::system.file("extdata","importable_BGF_object.csv",package = "bgfanalyzer"))

# import a BGF from a '.RDS'-file
BGF_rds <- import_BGF_object(
      path = base::system.file("extdata","importable_BGF_object.RDS",package = "bgfanalyzer"))


bgfanalyzer documentation built on Sept. 26, 2026, 5:07 p.m.