new functionality: musoGetValues, musoCompareFiles

This commit is contained in:
Roland Hollós 2022-11-22 14:16:38 +01:00
parent 2607a19741
commit 9bb19a3336
2 changed files with 37 additions and 0 deletions

View File

@ -20,7 +20,9 @@ export(getFilesFromIni)
export(getyearlycum)
export(getyearlymax)
export(multiSiteCalib)
export(musoCompareFiles)
export(musoDate)
export(musoGetValues)
export(musoGlue)
export(musoMapping)
export(musoMappingFind)

View File

@ -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)
})
}