-1

I am trying a simple Rmarkdown doc using the {bash} tag I need to issue a command with sudo Clearly the markdown engine fails on this task

Any idea how to pass sudo password to a markdown document

Thanks in advance for any help

Follows a reproducible example

---

title: "test"

author: "Andrea"

date: "9/15/2020"

output: html_document

---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

text here

```{bash}
ls
```

```{bash}
sudo su
ls
```
Ralf Stubner
  • 26,263
  • 3
  • 40
  • 75
Andrea
  • 593
  • 2
  • 8
  • Does this answer your question? https://stackoverflow.com/a/23188091/12957340 (e.g. something like `system("sudo -ks ls", input = password)` <- sudo has a bunch of options that might suit: https://www.sudo.ws/man/1.8.13/sudo.man.html) – jared_mamrot Sep 15 '20 at 10:25
  • Not really, I am inside a RMarkdown document. Moreover, I would like to type sudo pwd only once rather that one time for each chunk where I am using sudo – Andrea Sep 15 '20 at 10:49

1 Answers1

1

Possibly I have a solution

Open a terminal and issue any command with sudo: i.e. sudo pwd

Than run

R -e "rmarkdown::render('test.Rmd',output_file='test.html')"
Andrea
  • 593
  • 2
  • 8