Learn R Programming

pems.utils (version 0.3.0.7)

1.1.make.import.data: making and importing data

Description

Various pems.utils functions to make and import data as pems objects.

Usage

#making pems objects
 
is.pems(x, full.test = TRUE, ...)

pems(x, units = NULL, constants = NULL, history = NULL, ...)

pems.element(x, name = NULL, units = NULL, ...)

#associated

isPEMS(...) makePEMS(...) makePEMSElement(...) rebuildPEMS(x, ...)

# S3 method for data.frame as.pems(x, ...)

#importing data as pems objects

#general

import2PEMS(file.name = file.choose(), ..., file.reader = read.delim, output="pems")

importTAB2PEMS(..., file.reader = read.delim)

importCSV2PEMS(..., file.reader = read.csv)

#Horiba OBS

importOBS2PEMS(file.name = file.choose(), pems = "Horiba OBS", constants = NULL, history = NULL, analytes = c("co", "co2", "nox", "hc"), fuel = c("petrol", "diesel", "gasoline"), ...)

importOB12PEMS(file.name = file.choose(), pems = "Horiba OBS", constants = NULL, history = NULL, analytes = c("co", "co2", "nox", "hc"), fuel = c("petrol", "diesel", "gasoline"), ...)

#3DATX parSYNC

importParSYNC2PEMS(file.name = file.choose(), reset.signals = TRUE, history = NULL, constants = NULL, pm.analyzer = "parSYNC", ... )

#3DATX CAGE importCAGE2PEMS(..., calibrator = "CAGE")

#Sensors Inc SEMTECH

importSEMTECH2PEMS(file.name = file.choose(), history = NULL, constants = NULL, pems = "SEMTECH", ...)

#RoyalTek GPS

importRoyalTek2PEMS(file.name = file.choose(), file.type = c("special", "txt", "nmea"), vbox = "RoyalTEk", history = NULL, constants = NULL, ...)

#KML files

importKML2PEMS(file.name = file.choose(), history = NULL, constants = NULL, source = "Unknown", ...)

Value

is.pems return a logical, TRUE if the supplied object is pems class, otherwise FALSE. If the argument full.test = TRUE is also supplied, additional information about the object is returned as comment(output).

pems and pems.element functions return pems and pems.element

objects, respectively, made using the supplied file and any additional information also supplied in the same call.

rebuildPEMS rebuilts the supplied pems object. The default rebuilds as the lastest build structure.

import... functions return a pems object, made using the supplied file and any additional information also supplied in the same call.

Arguments

x

(A required object) For is.pems, any object to be tested as a pems object. For pems, an object to be used as the starting point to make a pems object, so typically a data.frame or another pems object. For pems.element, an object to be used as the starting point to make a pems.element. For rebuildPEMS, a pems object to be rebuilt.

full.test

(Logical) For is.pems, should the full pems test be applied and the pems structure confirmed?

...

(Optional) Other arguments, handling varies. For is.pems these are ignored. For pems these are added to the pems object unmodified. For import... functions, these are passed on and added to the constants component of the pems object. Note: This different handling is experimental and may be subject to change in future.

units, constants, history

(Default pems arguments) These are arguments that are routinely generated for pems objects. units holds unit ids for unit management, constants holds constants that should used specifically with data in the pems object, and history holds the pems object modification history.

name

(Default pems.element argument) name (and units) are arguments that are routinely generated for pems.element objects.

file.name

(file connection, etc.) For import... functions, the file/source to be imported. Note: the default, file.name = file.choose(), automatically opens a file browser if this argument is not supplied.

file.type, file.reader

Data reader parameters for some import... functions. file.type is the type of file to be imported. Note: Some import... functions can handle more than one file type, and file.type = "[option]" should be used to identify these. (Note: file.type options are typically file type identifiers, such as the file extensions, and a default 'special', which leaves the choice to the function. This way this option can typically be ignored unless, e.g. the function does not recognise the file type but the user knows it and wants to force the method.) file.reader identifies the R method/function that should be used to read data from the supplied file. For example, for importTAB2PEMS and importCSV2PEMS, by default, these are the standard R read... functions read.delim and read.csv, respectively.

output

Where included in formal arguments, an option to control function output.

pems, vbox, pm.analyzer, calibrator, source

(Character vectors) For some import... functions, data source descriptions may be automatically added to the pems object. pems and vbox are two examples, but others, such as vehicle and fuel descritpions can also be added in a similar fashion. Note: These are for user-reference, so can say whatever you want.

analytes

(Character vector) For import... functions, the names of any pems elements to be tagged as analyte concentrations. Note: If the PEMS unit reports concentrations rather than emissions it is often useful to identify these at import to avoid confusion, and to simplify later handling. So, if encountered, analyte names are prefixed with the term 'conc.'.

fuel

Some import... functions that handle exhaust monitoring system data may assume fuel types when calibrating inputs or calculating constants. In such cases the fuel argument is also included to identify which fuel was used.

reset.signals

(Logical or Character vector) For importParSYNC2PEMS, should any raw signal be reset? The default (TRUE) reverses the sign of opacity and ionization signals.

Author

Karl Ropkins

Details

is.pems tests if an object is/is not a pems object.

pems makes a pems object using supplied data and information.

pems.element makes a pems.element object using supplied data and information.

as.pems... functions attempt to convert a supplied object into a pems object. Currently, there is only a data.frame method and (by default) a pems method.

isPEMS, makePEMS and makePEMSElement are historical code, retained for backward compatibility.

rebuildPEMS rebuilds pems object as a different build version.

Crude import... functions import simple file structures, and are useful for getting data quickly into R:pems.utils. importTAB2PEMS imports tab delimited files and clipboard content. importCSV2PEMS imports comma delimited files. Both assume a simple file structure (i.e. data series in columns with names as headers), but require some time data management by the user. Note: These are wrappers for import2PEMS.

Other import... import specific file types.

importOBS2PEMS imports standard Horiba OBS files and converts them to pems objects. See Notes below.

importOB12PEMS imports .OB1 files and converts them to pems objects. OB1 files are generated by a Visual Basic PEMS data handler used during the RETEMM project. Notes below.

importParSYNC2PEMS imports standard parSYNC files and converts them to pems objects. See Notes below.

importCAGE2PEMS imports standard CAGE files and converts them to pems objects. See importParSYNC2PEMS Notes below.

importSEMTECH2PEMS imports Sensors Inc. SEMTECH ECOSTAR files and converts them to pems objects. See Notes below.

importRoyalTek2PEMS imports .txt and .nmea format Royal Tek GPS files and converts them to pems objects. See Notes below.

importKML2PEMS imports .kml format KML files and converts them to pems objects. See Notes below.

References

References in preparation.

See Also

See ref.unit.conversions and convertUnits for general unit handling; merge.pems for pems data merging and alignment.

Examples

Run this code

###########
##example 1 
###########

#make little pems

data <- data.frame(speed=1:10, emissions=1:10)
units <- c("m/s", "g/s")
pems <- pems(x = data, units=units, example="my record") 
 
pems                       #the pems object
summary(pems)              #summary of held data
pems$speed                 #the speed pems.element

#import data file as pems using import... functions

#For example, to import CSV file as pems object 
if (FALSE) {
pems <- importCSV2PEMS() 
}

Run the code above in your browser using DataLab