rtry_import {rtry}R Documentation

Import data

Description

This function imports a data file as a data.table for further processing. The default arguments are set to import tabulartor delimited data files in text format (.txt) exported from the TRY database. It can also be used to import other file formats, such as .csv files with comma separated values.

Usage

rtry_import(
  input,
  separator = "\t",
  encoding = "Latin-1",
  quote = "",
  showOverview = TRUE
)

Arguments

input

Path to the data file.

separator

Default "\t" for the TRY data output. Data separator.

encoding

Default "Latin-1". File encoding.

quote

Default "" reads the fields as is. If the fields in the data file are by a double quote, use "\"" instead.

showOverview

Default TRUE displays the input path, the dimension and the column names of the imported data.

Value

A data.table.

References

This function makes use of the fread function within the data.table package.

Examples

# Example 1: Import data exported from the TRY database
# Specify file path to the raw data provided within the rtry package
input_path <- system.file("testdata", "data_TRY_15160.txt", package = "rtry")

# For own data and Windows users the path might rather look similar to this:
# input_path <- "C:/Users/User/Desktop/data_TRY_15160.txt"

# Import data file using rtry_import
input <- rtry_import(input_path)

# Explicit notation:
# input <- rtry_import(input_path, separator = "\t", encoding = "Latin-1",
#            quote = "", showOverview = TRUE)

# Expected message:
# input: ~/R/R-4.0.5/library/rtry/testdata/data_TRY_15160.txt
# dim:   1782 28
# col:   LastName FirstName DatasetID Dataset SpeciesName AccSpeciesID AccSpeciesName
#        ObservationID ObsDataID TraitID TraitName DataID DataName OriglName
#        OrigValueStr OrigUnitStr ValueKindName OrigUncertaintyStr UncertaintyName
#        Replicates StdValue UnitName RelUncertaintyPercent OrigObsDataID ErrorRisk
#        Reference Comment V28

# Example 2: Import CSV file
# Specify file path to the raw data provided within the rtry package
input_path <- system.file("testdata", "data_locations.csv", package = "rtry")

# Import data file using rtry_import
input <- rtry_import(input_path, separator = ",", encoding = "UTF-8",
           quote = "\"", showOverview = TRUE)

# Expected message:
# input: ~/R/R-4.0.5/library/rtry/testdata/data_locations.csv
# dim:   20 3
# col:   Country code Country Location

[Package rtry version 1.1.0 Index]