Home > Enterprise >  RMarkdown: How to pass arguments to bash chunk defined as variables in R?
RMarkdown: How to pass arguments to bash chunk defined as variables in R?

Time:12-10

enter image description here

I added the shQuote() call after reading @Fravadona's comment: it is definitely a really good idea, since the path you are constructing may contain spaces or other special characters.

CodePudding user response:

Thank you @user2554330 for your suggestion. Indeed it seems to be working in the way I explained in my question. However, a little simpler solution was suggested here. Namely, don't use a bash chunk and instead create a string with full command and pass it to the system() function in R. In this case, I can do everything within the same environment.

```{r}
path_to_script <- glue("{here::here()}/bash_scripts/script.sh")
arg1 <- "something"
full_command <- glue("bash {path_to_script} {arg1}")
system(full_command)
```
  • Related