Search code examples
rrscript

How to source functions but not vectors in R script


I have an R script with several functions I made for multiple projects I have going on. There are also about 40 vectors of characters in this same script. The vectors contain key words I am looking for in different Twitter posts, and the function creates a dummy variable to identify if the posts contain those key words.

When I want to use the functions, I call source("myScript.R") to use those functions, but this also fills my environment with the 40 vectors, which I don't necessarily want to have happen.

Is there a way to mask the vectors so that when I run source (or some other call) then I will only see the functions in my environment and not the vectors?


Solution

  • Per @prosoitos 's comment above, I made a package with the R script containing my code and it worked like a charm