Skip to content

Commit

Permalink
Add lr_ prefix to all exported functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Bisaloo committed Oct 20, 2019
1 parent b915992 commit a0ed298
Show file tree
Hide file tree
Showing 33 changed files with 266 additions and 249 deletions.
26 changes: 13 additions & 13 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Generated by roxygen2: do not edit by hand

export(convert_tocsv)
export(get_metadata)
export(get_spec)
export(parse_abs)
export(parse_generic)
export(parse_jaz)
export(parse_jazirrad)
export(parse_jdx)
export(parse_procspec)
export(parse_roh)
export(parse_trm)
export(parse_trt)
export(parse_ttt)
export(lr_convert_tocsv)
export(lr_get_metadata)
export(lr_get_spec)
export(lr_parse_abs)
export(lr_parse_generic)
export(lr_parse_jaz)
export(lr_parse_jazirrad)
export(lr_parse_jdx)
export(lr_parse_procspec)
export(lr_parse_roh)
export(lr_parse_trm)
export(lr_parse_trt)
export(lr_parse_ttt)
importFrom(pbmcapply,pbmclapply)
importFrom(stats,approx)
importFrom(stats,setNames)
Expand Down
8 changes: 4 additions & 4 deletions R/convert_tocsv.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
#' @param overwrite logical. Should the function overwrite existing files with
#' the same name? (defaults to `FALSE`).
#'
#' @inheritParams get_spec
#' @inheritParams lr_get_spec
#'
#' @return Convert input files to csv and invisibly return the list of created
#' file paths
#'
#' @section Warning:
#'
#' This step loses all metadata associated to the spectra. This metadata is
#' critical to ensure reproducibility. We recommended you use [get_metadata()]
#' to extract this information from your raw data
#' critical to ensure reproducibility. We recommended you use
#' [lr_get_metadata()] to extract this information from your raw data.
#'
#' @importFrom tools file_path_sans_ext
#' @importFrom utils write.csv
#'
#' @export
convert_tocsv <- function(where = getwd(), ext = "txt", decimal = ".",
lr_convert_tocsv <- function(where = getwd(), ext = "txt", decimal = ".",
sep = NULL, subdir = FALSE,
cores = getOption("mc.cores", 2L), ignore.case = TRUE,
overwrite = FALSE) {
Expand Down
20 changes: 10 additions & 10 deletions R/dispatch_parser.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ dispatch_parser <- function(filename, decimal = ".", sep = NULL) {

switch(
tolower(file_ext(filename)),
procspec = parse_procspec(filename),
abs = parse_abs(filename),
roh = parse_roh(filename),
trm = parse_trm(filename),
trt = parse_trt(filename),
ttt = parse_ttt(filename),
jdx = parse_jdx(filename),
jaz = parse_jaz(filename),
jazirrad = parse_jazirrad(filename),
parse_generic(filename, decimal = decimal, sep = sep)
procspec = lr_parse_procspec(filename),
abs = lr_parse_abs(filename),
roh = lr_parse_roh(filename),
trm = lr_parse_trm(filename),
trt = lr_parse_trt(filename),
ttt = lr_parse_ttt(filename),
jdx = lr_parse_jdx(filename),
jaz = lr_parse_jaz(filename),
jazirrad = lr_parse_jazirrad(filename),
lr_parse_generic(filename, decimal = decimal, sep = sep)
)

}
8 changes: 4 additions & 4 deletions R/get_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' Finds and imports metadata from spectra files in a given location.
#'
#' @inheritParams get_spec
#' @inheritParams lr_get_spec
#'
#' @export
#'
Expand Down Expand Up @@ -34,10 +34,10 @@
#' Animal Behaviour. 2015 Aug 1;106:51–7 (\doi{10.1016/j.anbehav.2015.05.007}).
#'
#' @examples
#' get_metadata(system.file("testdata", package = "lightr"), ext = "ProcSpec",
#' subdir = TRUE)
#' lr_get_metadata(system.file("testdata", package = "lightr"),
#' ext = "ProcSpec", subdir = TRUE)

get_metadata <- function(where = getwd(), ext = "ProcSpec", sep = NULL,
lr_get_metadata <- function(where = getwd(), ext = "ProcSpec", sep = NULL,
subdir = FALSE, subdir.names = FALSE,
cores = getOption("mc.cores", 2L),
ignore.case = TRUE) {
Expand Down
6 changes: 3 additions & 3 deletions R/get_spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' Finds and imports reflectance/transmittance/absorbance data from spectra
#' files in a given location.
#'
#' @inheritParams parse_generic
#' @inheritParams lr_parse_generic
#'
#' @param where Folder in which files are located (defaults to current working
#' directory).
Expand Down Expand Up @@ -31,9 +31,9 @@
#' @importFrom stats approx
#'
#' @examples
#' get_spec(system.file("testdata", package = "lightr"), lim = c(400, 900))
#' lr_get_spec(system.file("testdata", package = "lightr"), lim = c(400, 900))
#'
get_spec <- function(where = getwd(), ext = "txt", lim = c(300, 700),
lr_get_spec <- function(where = getwd(), ext = "txt", lim = c(300, 700),
decimal = ".", sep = NULL, subdir = FALSE,
subdir.names = FALSE, cores = getOption("mc.cores", 2L),
ignore.case = TRUE) {
Expand Down
20 changes: 11 additions & 9 deletions R/parse_avantes_binary.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
#'
#' Parse Avantes binary file. <https://www.avantes.com/products/spectrometers>
#'
#' @inheritParams parse_generic
#' @inheritParams lr_parse_generic
#'
#' @inherit parse_generic return
#' @inherit lr_parse_generic return
#'
#' @importFrom stats setNames
#'
#' @examples
#' parse_trm(system.file("testdata", "avantes_trans.TRM", package = "lightr"))
#' parse_roh(system.file("testdata", "avantes_reflect.ROH", package = "lightr"))
#' lr_parse_trm(system.file("testdata", "avantes_trans.TRM",
#' package = "lightr"))
#' lr_parse_roh(system.file("testdata", "avantes_reflect.ROH",
#' package = "lightr"))
#'
#' @export
#'
parse_trm <- function(filename) {
lr_parse_trm <- function(filename) {
# Translation of the matlab script from:
# Copyright: (cc-by) Kotya Karapetyan, 2011.
# kotya.karapetyan@gmail.com
Expand Down Expand Up @@ -108,14 +110,14 @@ parse_trm <- function(filename) {
return(list(data, metadata))
}

#' @rdname parse_trm
#' @rdname lr_parse_trm
#'
#' @export
#'
parse_abs <- parse_trm
lr_parse_abs <- lr_parse_trm

#' @rdname parse_trm
#' @rdname lr_parse_trm
#'
#' @export
#'
parse_roh <- parse_trm
lr_parse_roh <- lr_parse_trm
16 changes: 9 additions & 7 deletions R/parse_avantes_converted.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
#' Parse Avantes converted file.
#' <https://www.avantes.com/products/spectrometers>
#'
#' @inheritParams parse_generic
#' @inheritParams lr_parse_generic
#'
#' @inherit parse_generic return
#' @inherit lr_parse_generic return
#'
#' @examples
#' parse_ttt(system.file("testdata", "avantes_export.ttt", package = "lightr"))
#' parse_trt(system.file("testdata", "avantes_export2.trt", package = "lightr"))
#' lr_parse_ttt(system.file("testdata", "avantes_export.ttt",
#' package = "lightr"))
#' lr_parse_trt(system.file("testdata", "avantes_export2.trt",
#' package = "lightr"))
#'
#' @export
#'
parse_ttt <- function(filename) {
lr_parse_ttt <- function(filename) {

# FIXME: grep to find appropriate lines instead of relying on fixed indices

Expand Down Expand Up @@ -67,8 +69,8 @@ parse_ttt <- function(filename) {

}

#' @rdname parse_ttt
#' @rdname lr_parse_ttt
#'
#' @export
#'
parse_trt <- parse_ttt
lr_parse_trt <- lr_parse_ttt
9 changes: 5 additions & 4 deletions R/parse_generic.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
#' * a list with metadata including
#'
#' @examples
#' parse_generic(system.file("testdata", "spec.csv", package = "lightr"),
#' sep = ",")
#' parse_generic(system.file("testdata", "CRAIC_export.txt", package = "lightr"))
#' lr_parse_generic(system.file("testdata", "spec.csv", package = "lightr"),
#' sep = ",")
#' lr_parse_generic(system.file("testdata", "CRAIC_export.txt",
#' package = "lightr"))
#'
#' @export
#'

parse_generic <- function(filename, decimal = ".", sep = NULL) {
lr_parse_generic <- function(filename, decimal = ".", sep = NULL) {

seps <- paste0(c("[[:blank:]]", sep), collapse = "|\\")

Expand Down
8 changes: 4 additions & 4 deletions R/parse_jdx.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
#'
#' Parse OceanOptics JCAMP-DX (.jdx) file. <https://oceanoptics.com/>
#'
#' @inheritParams parse_generic
#' @inheritParams lr_parse_generic
#'
#' @inherit parse_generic return
#' @inherit lr_parse_generic return
#'
#' @references McDonald RS, Wilks PA. JCAMP-DX: A Standard Form for Exchange of
#' Infrared Spectra in Computer Readable Form. Applied Spectroscopy.
#' 1988;42(1):151‑62.
#'
#' @examples
#' parse_jdx(system.file("testdata", "OceanOptics.jdx", package = "lightr"))
#' lr_parse_jdx(system.file("testdata", "OceanOptics.jdx", package = "lightr"))
#'
#' @export
#'
parse_jdx <- function(filename) {
lr_parse_jdx <- function(filename) {
content <- readLines(filename)
author <- grep("^##OWNER=", content, value = TRUE)
author <- gsub("^##OWNER= ", "", author)[1]
Expand Down
15 changes: 8 additions & 7 deletions R/parse_oceanoptics_converted.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
#'
#' Parse OceanOptics converted file. <https://oceanoptics.com/>
#'
#' @inheritParams parse_generic
#' @inheritParams lr_parse_generic
#'
#' @inherit parse_generic return
#' @inherit lr_parse_generic return
#'
#' @examples
#' parse_jaz(system.file("testdata", "jazspec.jaz", package = "lightr"))
#' parse_jazirrad(system.file("testdata", "irrad.JazIrrad", package = "lightr"))
#' lr_parse_jaz(system.file("testdata", "jazspec.jaz", package = "lightr"))
#' lr_parse_jazirrad(system.file("testdata", "irrad.JazIrrad",
#' package = "lightr"))
#'
#' @export
#'
parse_jaz <- function(filename) {
lr_parse_jaz <- function(filename) {

# METADATA

Expand Down Expand Up @@ -104,8 +105,8 @@ parse_jaz <- function(filename) {
return(list(data.frame(data_final), metadata))
}

#' @rdname parse_jaz
#' @rdname lr_parse_jaz
#'
#' @export
#'
parse_jazirrad <- parse_jaz
lr_parse_jazirrad <- lr_parse_jaz
11 changes: 6 additions & 5 deletions R/parse_procspec.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
#'
#' Parse OceanOptics ProcSpec file. <https://oceanoptics.com/>
#'
#' @inheritParams parse_generic
#' @inheritParams lr_parse_generic
#'
#' @inherit parse_generic return
#' @inherit lr_parse_generic return
#'
#' @importFrom xml2 read_xml xml_find_all xml_find_first xml_text
#'
#' @references <https://oceanoptics.com/faq/extract-data-procspec-file-without-spectrasuite/>
#'
#' @examples
#' parse_procspec(system.file("testdata", "procspec_files",
#' "OceanOptics_Linux.ProcSpec", package = "lightr"))
#' lr_parse_procspec(system.file("testdata", "procspec_files",
#' "OceanOptics_Linux.ProcSpec",
#' package = "lightr"))
#'
#' @export
#'
parse_procspec <- function(filename) {
lr_parse_procspec <- function(filename) {
# We let R find the suitable tmp folder to extract files
tmp <- tempdir()
on.exit(unlink(tmp))
Expand Down
Loading

0 comments on commit a0ed298

Please sign in to comment.