Rmarkdown password with getPass

Viewed 3048

I am building an application in RMarkdown that relies upon a user-generated password:

library(getPass)

pw <- getPass(msg = "Enter the Password, please!")

When I run all of the code interactively in the R console, the getPass function pauses the code and provides a popup window in which a user can enter the password.

However, when including this code in RMarkdown, the knitting process does not halt for getPass to do its work. As a result, the code runs without the password. In this case, it prevents the application from connecting to the password-protected database.

Do any of you have a recommendation for how to resolve this issue? I have searched for similar questions, but if this is a duplicate, then my apologies. Thank you!

1 Answers

As stated in comment use parameterized report.

Your rmarkdown should look like:

---
output: html_document
params:
  pwd:
    label: "Enter the Password, please!"
    value: ""
    input: password
---

Your password is `r params$pwd`

Now either run

rmarkdown::render("test.Rmd", params="ask")

or use RStudio button "Knitr with parameters":

where to klik

Related