Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide/asterisk a part of the code in R?

Tags:

r

I have put in a password inside my code in Rstudio and I just want to somehow make it unclear so when I show my code to someone they don't see the password. Any suggestions for how to do this? Thanks much

like image 409
Mohammad Avatar asked Dec 01 '22 00:12

Mohammad


2 Answers

you should make a new R script (let's call it login_credentials.R) and store your password there

username <- "username_here"
password <- "password_here"

Once you save that, you can then load that script using source()

This will load the username and password variables.

source(login_credentials.R)
> username
[1] "username_here"
> password
[1] "password_here"    

login_function(username,password)
like image 61
Ken Yeoh Avatar answered Dec 05 '22 03:12

Ken Yeoh


You can obscure your password in the source file.

You can run something like

dput(charToRaw("Password"))
# as.raw(c(0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64))

to get numeric dump of your password. Then you can include in your script

pwd <- as.raw(c(0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64))
login("username", rawToChar(pwd))

That will at least make it less-human-readable and there won't be a variable in the environment browser with the text value (at least I think, i'm not sure how RStudio displays raw data).

like image 22
MrFlick Avatar answered Dec 05 '22 02:12

MrFlick