1

I have the API credentials in one separate R script to keep it out of Git. I want to run this script in the beginning of the scripts that actually interact with the different servers. I have successfully used the same strategy for all my global functions.

setwd("G:/script")
source("API_credentials.R")  # gives always an error 

# > source("API_credentials.R")
# Error: '\s' is an unrecognized escape in character string starting ""g:\s"

source("ProVeg_functions.R") # runs fine

Problem:

Why does the first source() not work, while the second one does? The error message does not make any sense to me.

Solutions tried:

  1. I have tried different escape chars \.
  2. I have tried writing full path & file names.
  3. I have tried putting the file name in as a variable, which gets its content from a dir() search, to make sure that the file exists and the name is correctly written.
  4. Order of source() does not change situation.
  5. Isolating the piece of code with error, and restarting R.
  6. upgraded all my packages and R to version 4.0.2.
  7. The API_credentials.r script works fine when run on its own. the Sys.setenv() works fine and I can read the API keys with Sys.getenv().
  8. I am not sure if it is related to my problem, but if I do usethis::edit_r_environ() I can not see my API keys.

Setup Windows 10, R-Studio 1.3.1093, R version 4.0.2 (2020-06-22)

Eero
  • 11
  • 3
  • have you tried running `traceback()` after the error? It gives the full sequence of errors and can help pinpoint what in the file is causing the problem. I have had issues with uncommon characters before. I think I followed advice in the following link e.g. adding `encoding="utf-8"`, but this may be a different issue https://stackoverflow.com/questions/5031630/how-to-source-r-file-saved-using-utf-8-encoding – Jonny Phelps Oct 08 '20 at 13:13
  • @Jonny Yes, I have tried 'traceback()', but it does not provide any useful info. It says only: '1: source("API_credentials.R")' – Eero Oct 08 '20 at 13:24

1 Answers1

0

I mistakenly assumed that the error message was related to the script calling the API_credentials.R, but it actually was an error message indicating an error in the API_credentials.R script. Fixed a typo and all is good.

Eero
  • 11
  • 3