Here's the source for test_file
:
function (path, reporter = "summary")
{
reporter <- find_reporter(reporter)
with_reporter(reporter, {
sys.source(path, new.env(parent = globalenv()), chdir = TRUE)
end_context()
})
}
The key line is this:
sys.source(path, new.env(parent = globalenv()), chdir = TRUE)
The file is executed in a new environment under the global environment, while your newvar
is only available in a local environment of your creation.
What exactly is your end goal here? We can try to help. Or were you just curious?