Error in file(filename, “r”, encoding = encoding) : cannot open the connection

In your case try to add setwd("path/to/project/") in main.R where path/to/project/ contains main.R.

Then you can source functions.R either directly by source("functions.R") if both files lie in the same directory or source("sub-folder/functions.R") if the latter file is contained in a sub-folder.

If you’re not working on a RStudio project, chances are the working directory of main.R might be your home directory.

Leave a Comment

tech