Code Diagnostics across multiple files

Hello,
I am new to RStudio and I have observed that code diagnostics across multiple r files doesn't work as I expected.

I have the following structure:

project/
--project.Rproj
--main.r
--source/
----my_function.r

content of main.r:

source("source/my_function.r")
my_function()

content of my_function.r:

my_function <- function(){
print("Hello")
}

After calling source("source/my_function.r") my_function is in the Global Environment.
I can use ctrl-click on my_function() in main.r to get to the definition but I still get a warning symbol in main.r saying "no symbol named 'my_function' in scope" because there is no my_function defined within main.r. This warning is not useful.

Can I make code diagnostics to take into account the sourced file and not show a warning in this case? (Without disabling this type of warning in general.)

This might be the problem—different working directory that doesn't contain a source folder. To easily fix

Create a new project, if you don't have one already, and copy the relevant files there if not already. Then add `here::here("source/my_function.r") and it should be found.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.