wrathematics / getPass

Password function for R with masking (where supported)
Other
47 stars 5 forks source link

getPass knit error (macOS) #17

Open obregos opened 1 year ago

obregos commented 1 year ago

Running the following code in my .Rmd file does not produce the expected output when I Knit the .Rmd. There is no prompt and the html document is returned with no additional information.

knitr::opts_chunk$set(echo = TRUE)
library(getPass)
x <- getPass::getPass("Enter Something")

Running the code in the console works and displays a prompt that can be entered and returned correctly. However, the knit does not provide a prompt.

If you are having issues using the package, please provide some platform information which you can determine with the following R code:

# Interface
RStudio

# OS
Darwin

If your interface is RStudio, please provide the following additional information:

# RStudio version
R version 4.2.3 (2023-03-15)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 11.6.5

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] keyring_1.3.1   Hmisc_5.1-0     redcapAPI_2.7.0

loaded via a namespace (and not attached):
 [1] tidyselect_1.2.0  xfun_0.39         sodium_1.2.1      colorspace_2.1-0  vctrs_0.6.2       generics_0.1.3    htmltools_0.5.5   yaml_2.3.7       
 [9] base64enc_0.1-3   chron_2.3-61      utf8_1.2.3        rlang_1.1.1       pillar_1.9.0      foreign_0.8-84    glue_1.6.2        rappdirs_0.3.3   
[17] lifecycle_1.0.3   stringr_1.5.0     munsell_0.5.0     gtable_0.3.3      htmlwidgets_1.6.2 evaluate_0.21     knitr_1.42        fastmap_1.1.1    
[25] curl_5.0.0        fansi_1.0.4       htmlTable_2.4.1   scales_1.2.1      backports_1.4.1   filelock_1.0.2    checkmate_2.2.0   gridExtra_2.3    
[33] ggplot2_3.4.2     askpass_1.1       digest_0.6.31     stringi_1.7.12    dplyr_1.1.2       getPass_0.2-2     grid_4.2.3        cli_3.6.1        
[41] tools_4.2.3       magrittr_2.0.3    tibble_3.2.1      Formula_1.2-5     cluster_2.1.4     pkgconfig_2.0.3   data.table_1.14.8 httr_1.4.6       
[49] assertthat_0.2.1  rmarkdown_2.21    rstudioapi_0.14   R6_2.5.1          rpart_4.1.19      nnet_7.3-18       compiler_4.2.3

# rstudioapi version
0.14
spgarbet commented 1 year ago

I am confused by this. We tested .Platform$GUI and it returns 'RStudio' in the Mac environment when knit. If we run rstudioapi::askForPassword("Yo") directly in the Rmd it works on Mac, but getPass doesn't. This doesn't make sense.

spgarbet commented 1 year ago

I've modified our code to do the following

.default_pass <- function()
{
  if(grepl('mac', tolower(utils::osVersion))        &&
     requireNamespace("rstudioapi", quietly = TRUE) &&
     rstudioapi::isAvailable(child_ok=TRUE))
  {
    rstudioapi::askForPassword
  } else getOption('askpass', default = getPass::getPass)
}

This works on a Mac when pushing the knit button.