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:
Hope that gives you a way into the problem.