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.
Thanks for your reply.
I source the user defined function using base "source" i.e. source("udffilename.R")
I clear the workspace out completely before starting.
I have tried uploading screen shots of the RStudio IDE screen but, as a new user, I am for some reason, prohibited from doing so. What you are seeing is what I have always seen...until now.
Again...thanks so much for giving this your attention. I have identified the source of the problem. Your questions motivated me to think about what code was actually in the user define functions and why. The main calling program loads packages and clears the environment with " rm(list = ls()) ". I also had, no good reason, the command " rm(list = ls()) " at the top of each of the user defined function scripts. So every time a UDF was called it cleared the global environment. When I commented out this line in the functions all worked as expected. I am more than a little embarrassed. Thanks for asking the right questions.