diff --git a/R/fgetl-fopen.R b/R/fgetl-fopen.R new file mode 100644 index 0000000..176a330 --- /dev/null +++ b/R/fgetl-fopen.R @@ -0,0 +1,27 @@ +#' @title Read line from file, removing newline characters +#' @description Equivalent function to its homonymous Matlab equivalent. +#' @param file character vector to be read, usually an output of `fopen()` +#' @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. +#' @author Waldir Leoncio +#' @seealso fopen +#' @export +fgetl <- function(file) { + # ========================================================================== + # Validation + # ========================================================================== + if (length(file) <= 1) return(-1) + # ========================================================================== + # Returning file minus the first line + # ========================================================================== + out <- file[-1] + return(out) +} + +#' @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 +#' @seealso fgetl +#' @export +fopen <- function(filename) readLines(filename) \ No newline at end of file diff --git a/man/fgetl.Rd b/man/fgetl.Rd new file mode 100644 index 0000000..cd49776 --- /dev/null +++ b/man/fgetl.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fgetl.R +\name{fgetl} +\alias{fgetl} +\title{Read line from file, removing newline characters} +\usage{ +fgetl(file) +} +\arguments{ +\item{file}{character vector to be read, usually an output of `fopen()`} +} +\value{ +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. +} +\description{ +Equivalent function to its homonymous Matlab equivalent. +} +\seealso{ +fopen +} +\author{ +Waldir Leoncio +} diff --git a/man/fopen.Rd b/man/fopen.Rd new file mode 100644 index 0000000..3e2d3a7 --- /dev/null +++ b/man/fopen.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fgetl.R +\name{fopen} +\alias{fopen} +\title{Open file} +\usage{ +fopen(filename) +} +\arguments{ +\item{filename}{Path and name of file to be open} +} +\value{ +The same as `readLines(filename)` +} +\description{ +Open a text file +} +\seealso{ +fgetl +} +\author{ +Waldir Leoncio +}