I could source it in R (terminal), and functions in this script worked well; but it did not work in RStudio, both on Mac and Ubuntu. This problem seemed related to different environment path between terminal and RStudio.
I recently had a frustrating problem where the reverse was true. To troubleshoot you could do a
Sys.getenv()
in each environment immediately after opening a fresh session & compare. I ended up saving the working environment into a file after adding = between each pair, reading it into a fresh session in the failing environment with a readRenviron('dotenvFile'), confirming that the code now worked, then commenting out chunks of the dotenv file & repeating the exercise until I worked out which environment variable(s) were at fault.
Once you've worked out the culprits you could make sure they're set (or unset) appropriately as here: