From 9bb19a3336787898511c6063cc57620c83723b4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20Holl=C3=B3s?= Date: Tue, 22 Nov 2022 14:16:38 +0100 Subject: [PATCH] new functionality: musoGetValues, musoCompareFiles --- RBBGCMuso/NAMESPACE | 2 ++ RBBGCMuso/R/changeMuso.R | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/RBBGCMuso/NAMESPACE b/RBBGCMuso/NAMESPACE index d4fd11c..0fc6ec6 100644 --- a/RBBGCMuso/NAMESPACE +++ b/RBBGCMuso/NAMESPACE @@ -20,7 +20,9 @@ export(getFilesFromIni) export(getyearlycum) export(getyearlymax) export(multiSiteCalib) +export(musoCompareFiles) export(musoDate) +export(musoGetValues) export(musoGlue) export(musoMapping) export(musoMappingFind) diff --git a/RBBGCMuso/R/changeMuso.R b/RBBGCMuso/R/changeMuso.R index d6a156c..a0b4789 100644 --- a/RBBGCMuso/R/changeMuso.R +++ b/RBBGCMuso/R/changeMuso.R @@ -31,3 +31,38 @@ changeByIndex <- function (rowIndex, parameter, fileStringVector){ fileStringVector[i] <- changeNth(fileStringVector[i], h, parameter) fileStringVector } + + +#' musoGetValues +#' +#' Get values from a musofile by supplying muso indices +#' +#' @param filename The name of the musofile we want the value from (e.g. epc file) +#' @param indices muso indices +#' @usage musoGetValues(filename, indices) +#' @export + +musoGetValues <- function(filename, indices){ + sapply(indices, function(index){ + colIndex <- round((index*100) %% 10) + 1 + rowIndex <- as.integer(index) + as.numeric(unlist(strsplit(readLines(filename)[rowIndex],split="\\s+"))[colIndex]) + +}) +} + +#' musoCompareFiles +#' +#' A simple wrapper function based on musoGetValues where you can get multiple values from multiple files +#' using the supplied indices. It is useful for comparing files. +#' +#' @param filenames The name of the files where you can get the data from +#' @param indices muso indices +#' @usage musoCompareFiles(filenames, indices) +#' @export + +musoCompareFiles <- function(filenames, indices){ + sapply(filenames, function(fn){ + musoGetValues(fn,indices) + }) +}