R/template_read.R

Defines functions template_read

Documented in template_read

#' Read a template from a csv file
#' @description The template should be created using \code{create_template()}
#' @param file A character vector with the path to the csv file
#' @returns a data.frame with the content of the csv file
#' @examples
#' # Create a temporary file for this example
#' file <- tempfile()
#'
#' # Create a template and save it to a csv file
#' template_create(authors = c("Josep Maria", "Jane Doe"), file = file)
#'
#' # Read the template back (in real life once it has been populated)
#' template_read(file)
#' @export
#' @importFrom utils write.csv2 read.csv2

template_read <- function(file){

  file <- normalizePath(file)

  cras_table <- read.csv2(file, check.names = FALSE)

  if(!("Authors" %in% names(cras_table)))
    stop("A column named `Authors` is missing")

  if(nrow(cras_table) < 1)
    stop("The cras_table has zero rows")

  if(!is.character(cras_table$Authors))
    warning("Authors column is not of type character")

  if(!all(vapply(cras_table[-1], is.numeric, FALSE)))
    warning("Roles are not numeric, it can lead to unexpected behaviour")

  return(cras_table)

}

Try the CRediTas package in your browser

Any scripts or data that you put into this service are public.

CRediTas documentation built on April 14, 2023, 12:30 a.m.