You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found the method to create environment variables using .Renviron and call it to set the variables. From what I understand, .Renvrion is used as API key protection, but this file should be ignored in the .gitignore file.
You would set up the .Renvrion by usethis::edit_r_environ("project") for the project level (or using "user" for computer level), then edit:
<UNQUOTED_KEY_VALUE> = "<quoted key>"
# Note: this won't work if you use `<-`,
# use `=`, the only time to do this for setting a variable
After restarting R, you will have access to the environment, but to actually set it to a variable:
global_var <- Sys.getenv("<quoted <UNQUOTED_KEY_VALUE>>") # the key needs to be quoted
Calling the "key value" can be done in the .Rprofile file too because this file is executed after the .Renviron. Edit .Rprofile using usethis::edit_r_profile("project").
My thought would be to have a function that will edit the .Renviron function when creating a new cruise ID to include the cruise ID, like <CRUISE_ID> = "<cruise id>". Then, calling the last cruise in a list from the .Rprofile where there is a vector of cruise IDs and the user would select one from the list and would be set
# vector of cruise IDs
cruise_id_select <- c("<cruise ID1>", "<cruise ID2>", "<cruise ID etc>")
# ask which cruise to set
cruise_id_select <- menu(cruise_id_select)
# or have it use the last in the list?
cruise_id_select <- cruise_id_select[length(cruise_id_select)]
# set cruise_id using the key value from `cruise_id_select`
cruise_id <- Sys.getenv(cruise_id_select)
@7yl4r
I found the method to create environment variables using
.Renviron
and call it to set the variables. From what I understand,.Renvrion
is used as API key protection, but this file should be ignored in the.gitignore
file.You would set up the
.Renvrion
byusethis::edit_r_environ("project")
for the project level (or using "user" for computer level), then edit:After restarting R, you will have access to the environment, but to actually set it to a variable:
Calling the "key value" can be done in the
.Rprofile
file too because this file is executed after the.Renviron
. Edit.Rprofile
usingusethis::edit_r_profile("project")
.Here is an example I have in my personal repo: .Renviron for Global Variables
Here is some more info about the order of operations when starting R:
The text was updated successfully, but these errors were encountered: