├── .Rbuildignore ├── .gitignore ├── NAMESPACE ├── DESCRIPTION ├── README.md ├── ptexamples.Rproj ├── inst └── rstudio │ └── templates │ └── project │ └── hello_world.dcf └── R └── hello_world.R /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: fake comment so roxygen2 overwrites silently. 2 | exportPattern("^[^\\.]") 3 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: ptexamples 2 | Title: Example RStudio Project Templates 3 | Author: Kevin Ushey 4 | Maintainer: Kevin Ushey 5 | Version: 0.0.1 6 | Description: Example package showcasing how RStudio project templates are defined. 7 | Depends: R (>= 3.3.2) 8 | License: GPL (>= 2) 9 | Encoding: UTF-8 10 | LazyData: true 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ptexamples 2 | 3 | This R package showcases how RStudio project templates can be defined and 4 | exposed within R packages. See 5 | https://rstudio.github.io/rstudio-extensions/rstudio_project_templates.html for 6 | more information. 7 | 8 | Install this package with: 9 | 10 | devtools::install_github("rstudio/ptexamples") 11 | -------------------------------------------------------------------------------- /ptexamples.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageRoxygenize: rd,collate,namespace 22 | -------------------------------------------------------------------------------- /inst/rstudio/templates/project/hello_world.dcf: -------------------------------------------------------------------------------- 1 | Binding: hello_world 2 | Title: Example Project Template 3 | OpenFiles: INDEX 4 | 5 | Parameter: check 6 | Widget: CheckboxInput 7 | Label: Checkbox Input 8 | Default: On 9 | Position: left 10 | 11 | Parameter: select 12 | Widget: SelectInput 13 | Label: Select Input 14 | Fields: Field A, Field B, Field C 15 | Default: Field B 16 | Position: left 17 | 18 | Parameter: text 19 | Widget: TextInput 20 | Label: Text Input 21 | Default: Hello, world! 22 | Position: right 23 | 24 | Parameter: file 25 | Widget: FileInput 26 | Label: File Input 27 | Default: ~/ 28 | Position: right 29 | -------------------------------------------------------------------------------- /R/hello_world.R: -------------------------------------------------------------------------------- 1 | # This function showcases how one might write a function to be used as an 2 | # RStudio project template. This function will be called when the user invokes 3 | # the New Project wizard using the project template defined in the template file 4 | # at: 5 | # 6 | # inst/rstudio/templates/project/hello_world.dcf 7 | # 8 | # The function itself just echos its inputs and outputs to a file called INDEX, 9 | # which is then opened by RStudio when the new project is opened. 10 | hello_world <- function(path, ...) { 11 | 12 | # ensure path exists 13 | dir.create(path, recursive = TRUE, showWarnings = FALSE) 14 | 15 | # generate header 16 | header <- c( 17 | "# This file was generated by a call to 'ptexamples::hello_world()'.", 18 | "# The following inputs were received:", 19 | "" 20 | ) 21 | 22 | # collect inputs 23 | dots <- list(...) 24 | text <- lapply(seq_along(dots), function(i) { 25 | key <- names(dots)[[i]] 26 | val <- dots[[i]] 27 | paste0(key, ": ", val) 28 | }) 29 | 30 | # collect into single text string 31 | contents <- paste( 32 | paste(header, collapse = "\n"), 33 | paste(text, collapse = "\n"), 34 | sep = "\n" 35 | ) 36 | 37 | # write to index file 38 | writeLines(contents, con = file.path(path, "INDEX")) 39 | 40 | } 41 | --------------------------------------------------------------------------------