Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rmarkdown password with getPass

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!

like image 539
DoubleTap Avatar asked Jun 30 '17 18:06

DoubleTap


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

like image 52
Marek Avatar answered Nov 09 '22 01:11

Marek