Learn R Programming

shotGroups (version 0.8.2)

readDataMisc: Read data from text files

Description

Reads data from text files that have a similar structure to OnTarget PC/TDS output files, specifically from Taran. Several files can be read with one call.

Usage

readDataMisc(fPath = ".", fNames, fPat, combine = TRUE,
            dstTarget, conversion)

Value

With combine=FALSE: a list of data frames, each from one file that was read in. This list can then be combined into one big data frame by combineData.

file1

data frame containing data from the first file

file2

data frame containing data from the second file

...

more data frames

With combine=TRUE: a combined data frame from combineData.

Arguments

fPath

a character string containing the path to the folder with the data files, e.g. 'c:/folder/otFiles'.

fNames

a character vector containing the file names of the files that should be read in.

fPat

a character string containing the regular-expression that describes all names of files that should be read in. E.g., '^points[[:digit:]]{2}\\.txt$' for filenames 'points**.txt', where ** are 2 digits. See regex, glob2rx.

combine

logical: combine the data into one big data frame with combineData?

dstTarget

a numerical value/vector giving the distance to the target - used in MOA calculation. Acts as override if variable distance is already included in the data.

conversion

how to convert the measurement unit for distance to target to that of the (x,y)-coordinates in MOA calculation. Example 'm2cm'. See getMOA.

Details

If fNames is provided, fPat is ignored.

If neither fNames nor fPat is provided, and we are in interactive mode under Windows, files can be chosen interactively.

This function is basically a wrapper for read.table and read.csv.

The files need to be either comma-separated or whitespace-delimited, and have a header with the variable names. Variable names must not contain spaces. In order to be later used by functions analyzeGroup or compareGroups, coordinates for points of impact must be given with point.x, point.y, x, y, or ShotX, ShotY. Point of aim can be given with aim.x, aim.y, otherwise (0,0) will be assumed in analysis functions. Distance to target can be given with distance, otherwise 100m will be assumed in analysis functions. Files should to contain the variable Group if combineData should be later used to combine them into one big data frame. There can only be exactly as many variable names as there are non-empty data-columns.

For reading in files exported from OnTarget PC 1.*, see readDataOT1.
For reading in files exported from OnTarget PC 2.* or OnTarget TDS v3.*, see readDataOT2.

See Also

read.table, regex, glob2rx, combineData, readDataOT1, readDataOT2, readDataSMT, readDataShotMarker

Examples

Run this code
if (FALSE) {
fPath   <- 'c:/folder/files'             # folder with data files
fileNam <- c('pts01.txt', 'pts02.txt')   # desired files in that folder
DFgroup <- readDataMisc(fPath, fNames=fileNam, combine=TRUE)

## alternatively, specify filename pattern for all files to be read in
fPath   <- 'c:/folder/otFiles'           # folder with data files
fPat    <- '^pts[[:digit:]]{2}\\.txt$' # filename pattern
DFgroup <- readDataMisc(fPath, fPat=pattern, combine=TRUE)
}

## result should look like this
data(DFcm)
head(DFcm)

Run the code above in your browser using DataLab