Run a selected lines as background job including libraries

so I found out it is possible to run selected lines as a background job under Code > Run Selection as Background Job (or with an assigned hotkey). This is awesome!
Anyways I still have a small problem: apparently the libraries are not imported. Adding the tick to "Run job with copy of global environment" does not help.

Is there any way to initiate the selected lines as a background job with all currently loaded libraries included? Of course I could just add the libraries to the lines, but this would be very laborious.

Thank you very much for the help.

1 Like

I wonder if “environment” actually includes package namespace? A workaround might be to use calls like

d -> dplyr::filter(x == 5) |> …

Second thought

Create a separate script with just library() calls


Yes sure that would work, but I would never do that because it is tedious in my case. I feel like "Run Selection" should be a quick and easy thing to do, like running a couple of lines while working somewhere else on that script. The problem is, that some very fundamental functions like data.table and tidy will not work, so this is basically not usable except for base R.
An option to also include libraries with the global environment would be great.

This topic was automatically closed 42 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.