-
Notifications
You must be signed in to change notification settings - Fork 2
/
template_read.R
35 lines (27 loc) · 1.06 KB
/
template_read.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#' 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){
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)
}