| import_standard_record | R Documentation |
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.
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)
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 |
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: |
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 |
sub |
a |
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.
Either a data.frame, a list or a BGF
# 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"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.