#' Read a whitespace separated values (.wsv or .txt) file.
#'
#' This function will load a data set stored in the WSV file format into
#' the specified global variable binding.
#'
#' @param data.file The name of the data file to be read.
#' @param filename The path to the data set to be loaded.
#' @param variable.name The name to be assigned to in the global environment.
#'
#' @return No value is returned; this function is called for its side effects.
#'
#' @examples
#' library('ProjectTemplate')
#'
#' \dontrun{wsv.reader('example.wsv', 'data/example.wsv', 'example')}
#' @importFrom utils read.table
#' @importFrom utils unzip
wsv.reader <- function(data.file, filename, variable.name)
{
if (grepl('\\.zip$', filename))
{
tmp.dir <- tempdir()
tmp.path <- file.path(tmp.dir, data.file)
file.copy(filename, tmp.path)
unzip(filename, exdir = tmp.dir)
filename <- file.path(tmp.dir, sub('\\.zip$', '', data.file))
}
assign(variable.name,
read.table(filename,
header = config$data_loading_header),
envir = .TargetEnv)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.