R/write_FemFit.r

Defines functions write_FemFit

Documented in write_FemFit

#' Output an FemFit dataset
#'
#' @description
#' A wrapper function which calls \code{write.csv} for an "FemFit" object.
#'
#' @param x An "FemFit" object.
#' @param ... Arguments passed to \code{\link{write.csv}}.
#'
#' @details
#' Note that \code{write.csv} is a wrapper function to \code{write.table}. Hence, \code{write.csv} does not allow the end-user to set the \code{append}, \code{col.names}, \code{sep}, \code{dec}, and \code{qmethod} arguments.
#'
#' @seealso \code{\link{write.csv}}
#'
#' @examples
#' # Load in the FemFit dataset
#' session488 = read.FemFit("./Datasets_AukRepeat/2c2cc798481d05da_488_csv.zip")
#'
#' # Export the FemFit dataset from R into a CSV file
#' write_FemFit(session488, "./Export_AukRepeat/session488.csv")
#'
#' @export
write_FemFit = function(x, ...) {
  # Throw an error if the x argument is not an FemFit object or missing
  if (!inherits(x, "FemFit") || is.na(x)) {
    stop("The x argument is not an FemFit object.", call. = FALSE)
  }

  # Throw an error if the FemFit object does not have a `df` element
  if (!exists("df", x)) {
    stop("The provided FemFit object does not have a `df` element.", call. = FALSE)
  }

  write.csv(x = x$df, ...)
}
TheGreatGospel/IVPSA documentation built on May 19, 2019, 1:47 a.m.