r-lib / keyring

:closed_lock_with_key: Access the system credential store from R
https://keyring.r-lib.org/
Other
196 stars 28 forks source link

keyring knit error (macOS) #136

Closed obregos closed 1 year ago

obregos commented 1 year ago

The following code in my .Rmd does not work as expected when running Knit.

knitr::opts_chunk$set(echo = TRUE)

library(keyring)
keyring::keyring_unlock("API_KEYs")

Running this .Rmd chunk alone prompts me for my password and returns the keyring correctly. However, when I Knit the .Rmd file it does not prompt me for a password and returns the following error:

Error in b_macos_keyring_unlock(self, private, keyring, password) : 
  Aborted unlocking keyring

R.version: 4.2.3 MacOS Version 11.6.5 keyring version 1.3.1

gaborcsardi commented 1 year ago

keyring uses askpass::askpass() to read the password. This does not work non-interactively, but you can set the askpass option as a workaround. See the askpass documentation for details.