Here is a description of the problem. It happens both inside a project and outside a project (outside of a project I have set the working directory).
- I create several user defined functions. The code does what I want it to do without errors.
- I source one of the functions e.g. load_data()
- The function load_data appears in the global environment
- I assign a value to a variable using the one of the functions e.g. x <- load_data()
- The variable x appears in the global environment
- I source another of the functions e.g. load_parameters e.g. y <- load_parameters()
- The function load_parameters appears in the global environment
- The function load_data disappears from the global environment along with the variable x
When I source all the functions the user defined functions in a single script I get no error messages but only the last user defined function sourced appears in the global environment
When I call all the user defined functions as a group in a single script I get error messages on all but the last user defined function e.g.
Error in load_data() :
could not find function "load_data"
getwd() returns the subdirectory I am working in or the project subdirectory as applicable
searchpaths() returns a list of paths which includes the global environment but does not explicitly include the working directory
I have worked with user define functions before and this has never happened. I recently updated the version of R and RStudio and guess that it is some sort of configuration problem or preference.