2020-07-31 09:20:44 +02:00
|
|
|
#' @title Read line from file, removing newline characters
|
|
|
|
|
#' @description Equivalent function to its homonymous Matlab equivalent.
|
2020-07-31 09:26:57 +02:00
|
|
|
#' @param file character vector to be read, usually an output of `fopen()`
|
2022-07-28 15:47:36 +02:00
|
|
|
#' @return If the file is nonempty, then fgetl returns tline as a character
|
|
|
|
|
#' vector. If the file is empty and contains only the end-of-file marker, then
|
|
|
|
|
#' fgetl returns tline as a numeric value -1.
|
2020-07-31 09:20:44 +02:00
|
|
|
#' @author Waldir Leoncio
|
2020-07-31 09:26:57 +02:00
|
|
|
#' @seealso fopen
|
2020-07-31 09:20:44 +02:00
|
|
|
fgetl <- function(file) {
|
2021-11-10 14:02:35 +01:00
|
|
|
# ==========================================================================
|
|
|
|
|
# Validation
|
|
|
|
|
# ==========================================================================
|
|
|
|
|
if (length(file) <= 1) {
|
|
|
|
|
return(-1)
|
|
|
|
|
}
|
|
|
|
|
# ==========================================================================
|
|
|
|
|
# Returning file minus the first line
|
|
|
|
|
# ==========================================================================
|
|
|
|
|
out <- file[-1]
|
|
|
|
|
return(out)
|
2020-07-31 09:20:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#' @title Open file
|
|
|
|
|
#' @description Open a text file
|
|
|
|
|
#' @param filename Path and name of file to be open
|
|
|
|
|
#' @return The same as `readLines(filename)`
|
|
|
|
|
#' @author Waldir Leoncio
|
2020-07-31 09:26:57 +02:00
|
|
|
#' @seealso fgetl
|
2021-11-10 14:02:35 +01:00
|
|
|
fopen <- function(filename) readLines(filename)
|