How to programmatically generate R codes and directory structures with template

Viewed 413

I have the following Shiny-app, organize the following way

-- base_app
   |-- server.R
   |-- ui.R
   `-- www

For example, server.R contains this lines:

infile <- "foo.txt"
# do something with infile

I'm looking for a way to automatically generate the app directory and the file content. For example, if we define 2 parameters:

  1. App name mycool_app

  2. Input file: bar.txt

afterwards it will generate this based on the template defined in base_app.

-- mycool_app
   |-- server.R
   |-- ui.R
   `-- www

And the new server.R will contain infile <- "bar.txt".

I looked at whisker. But it doesn't provide the template encoded inside file, only through string. I'm thinking of the capability ala Python's Jinja2.

What are the best way to do it in R?


Update:

Another example for ui.R:

# Example of ui.R
# Choices differs from analysis to analysis
# Hand coded 
# ---------------------------
choices_list <- list(
                "A. Rumef.XXX vs Salt"            = "Group_A.Rumef.XXX_vs_Salt.iv",
                "B. Bra.XXX vs Salt"              = "Group_B.Bra.XXX_vs_Salt.iv",
                "C. Salt.Rumef vs Bra"            = "Group_C.Salt.Rumef_vs_Bra.iv",
                "D. XXX.Rumef vs Bra"             = "Group_D.XXX.Rumef_vs_Bra.iv"
                                                 )
selected_choices <- "Group_A.Rumef.XXX_vs_Salt.iv"
analysis_name <- "Cool Analysis"
fc_slider_threshold <- 0.8

# Do more things with those variables.

Content of choices_list, selected_choices, analysis_name, fc_slider_threshold will be supplied to be included in the newly generated mycool_app.

1 Answers
Related