Commit 6ec4c854 by Jan Wijffels

Add run_app

parent 34aad481
...@@ -9,5 +9,5 @@ Authors@R: c( ...@@ -9,5 +9,5 @@ Authors@R: c(
Description: Utilities for the Citizen Air application. Description: Utilities for the Citizen Air application.
License: CC-BY-SA-4.0 License: CC-BY-SA-4.0
RoxygenNote: 6.0.1 RoxygenNote: 6.0.1
Imports: readxl, cellranger, data.table, fasttime Imports: readxl, cellranger, data.table, fasttime, rmarkdown, tools, utils
Suggests: sp Suggests: sp
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
S3method(as.data.frame,citizenair) S3method(as.data.frame,citizenair)
export(read_citizenair) export(read_citizenair)
export(run_app)
importFrom(cellranger,cell_cols) importFrom(cellranger,cell_cols)
importFrom(cellranger,cell_limits) importFrom(cellranger,cell_limits)
importFrom(cellranger,cell_rows) importFrom(cellranger,cell_rows)
...@@ -12,6 +13,8 @@ importFrom(data.table,setnames) ...@@ -12,6 +13,8 @@ importFrom(data.table,setnames)
importFrom(fasttime,fastPOSIXct) importFrom(fasttime,fastPOSIXct)
importFrom(readxl,excel_sheets) importFrom(readxl,excel_sheets)
importFrom(readxl,read_excel) importFrom(readxl,read_excel)
importFrom(rmarkdown,run)
importFrom(tools,file_path_sans_ext)
importFrom(utils,capture.output) importFrom(utils,capture.output)
importFrom(utils,head) importFrom(utils,head)
importFrom(utils,tail) importFrom(utils,tail)
#' @importFrom readxl read_excel excel_sheets #' @importFrom readxl read_excel excel_sheets
#' @importFrom cellranger cell_rows cell_cols cell_limits #' @importFrom cellranger cell_rows cell_cols cell_limits
#' @importFrom utils head tail capture.output #' @importFrom utils head tail capture.output
#' @importFrom tools file_path_sans_ext
#' @importFrom data.table rbindlist melt.data.table setnames as.data.table #' @importFrom data.table rbindlist melt.data.table setnames as.data.table
#' @importFrom fasttime fastPOSIXct #' @importFrom fasttime fastPOSIXct
#' @importFrom rmarkdown run
NULL NULL
#' @title Run the app
#' @description Run the app
#' @param app a character string with the name of the app. Currently only 'citizenair.Rmd' is allowed.
#' @return nothing to return
#' @export
#' @examples
#' \dontrun{
#' run_app()
#' run_app('citizenair.Rmd')
#' }
run_app <- function(app = c("citizenair.Rmd")){
appfolder = tools::file_path_sans_ext(app)
app <- match.arg(app)
olddir <- getwd()
on.exit({
setwd(olddir)
})
# copy app to tempdir
appdir <- tempdir()
setwd(appdir)
dirs <- setdiff(list.dirs(path = system.file("apps", package = "citizenair"), recursive = TRUE, full.names = FALSE), "")
sapply(dirs, FUN=function(x) dir.create(x, recursive = TRUE, showWarnings = FALSE))
copyme <- data.frame(from = list.files(path = system.file("apps", package = "citizenair"), full.names = TRUE, recursive = TRUE),
to = file.path(appdir, list.files(path = system.file("apps", package = "citizenair"), full.names = FALSE, recursive = TRUE)),
stringsAsFactors = FALSE)
mapply(from = copyme$from, to = copyme$to, function(from, to){
file.copy(from = from, to = to, overwrite = TRUE)
})
# run the app
rmarkdown::run(sprintf("%s/%s", appfolder, app))
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/runapp.R
\name{run_app}
\alias{run_app}
\title{Run the app}
\usage{
run_app(app = c("citizenair.Rmd"))
}
\arguments{
\item{app}{a character string with the name of the app. Currently only 'citizenair.Rmd' is allowed.}
}
\value{
nothing to return
}
\description{
Run the app
}
\examples{
\dontrun{
run_app()
run_app('citizenair.Rmd')
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment