Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
41 lines (34 sloc) 1.1 KB
# This function showcases how one might write a function to be used as an
# RStudio project template. This function will be called when the user invokes
# the New Project wizard using the project template defined in the template file
# at:
#
# inst/rstudio/templates/project/hello_world.dcf
#
# The function itself just echos its inputs and outputs to a file called INDEX,
# which is then opened by RStudio when the new project is opened.
hello_world <- function(path, ...) {
# ensure path exists
dir.create(path, recursive = TRUE, showWarnings = FALSE)
# generate header
header <- c(
"# This file was generated by a call to 'ptexamples::hello_world()'.",
"# The following inputs were received:",
""
)
# collect inputs
dots <- list(...)
text <- lapply(seq_along(dots), function(i) {
key <- names(dots)[[i]]
val <- dots[[i]]
paste0(key, ": ", val)
})
# collect into single text string
contents <- paste(
paste(header, collapse = "\n"),
paste(text, collapse = "\n"),
sep = "\n"
)
# write to index file
writeLines(contents, con = file.path(path, "INDEX"))
}