From e5241ffb1c3bac81d5d449e6d85d741a92c32a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vilmantas=20G=C4=97g=C5=BEna?= Date: Tue, 10 Aug 2021 23:59:12 +0300 Subject: [PATCH] Use arg. `file` #43 --- vignettes/read_txt_PerkinElmer.R | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/vignettes/read_txt_PerkinElmer.R b/vignettes/read_txt_PerkinElmer.R index 2d3f658..19a3040 100644 --- a/vignettes/read_txt_PerkinElmer.R +++ b/vignettes/read_txt_PerkinElmer.R @@ -3,7 +3,7 @@ #' Read PerkinElmer file (ASCII/txt) #' -#' @param files Path to file. +#' @param file Path to file or several files #' @param ... Passed to [base::scan()]. #' @param label Labels. #' @@ -13,7 +13,7 @@ #' #' @export #' -read_txt_PerkinElmer <- function(files = stop("filenames needed"), +read_txt_PerkinElmer <- function(file = stop("filenames needed"), ..., label = list()) { @@ -27,31 +27,31 @@ read_txt_PerkinElmer <- function(files = stop("filenames needed"), label ) - if (length(files) == 0) { + if (length(file) == 0) { warning("No files found.") return(new("hyperSpec")) } ## read the first file - buffer <- matrix(scan(files[1], ...), ncol = 2, byrow = TRUE) + buffer <- matrix(scan(file[1], ...), ncol = 2, byrow = TRUE) ## first column gives the wavelength vector wavelength <- buffer[, 1] ## preallocate the spectra matrix: ## one row per file x as many columns as the first file has - spc <- matrix(ncol = nrow(buffer), nrow = length(files)) + spc <- matrix(ncol = nrow(buffer), nrow = length(file)) ## the first file's data goes into the first row spc[1, ] <- buffer[, 2] ## now read the remaining files - for (f in seq(along = files)[-1]) { - buffer <- matrix(scan(files[f], ...), ncol = 2, byrow = TRUE) + for (f in seq(along = file)[-1]) { + buffer <- matrix(scan(file[f], ...), ncol = 2, byrow = TRUE) ## check whether they have the same wavelength axis if (!all.equal(buffer[, 1], wavelength)) { - stop(paste(files[f], "has different wavelength axis.")) + stop(paste(file[f], "has different wavelength axis.")) } spc[f, ] <- buffer[, 2] @@ -61,7 +61,7 @@ read_txt_PerkinElmer <- function(files = stop("filenames needed"), spc <- new("hyperSpec", wavelength = wavelength, spc = spc, label = label) ## consistent file import behavior across import functions - .spc_io_postprocess_optional(spc, files) + .spc_io_postprocess_optional(spc, file) }