1

I'm using a package from github and functions in it are not... connected. The main file has a function but to make that function work i need to run 4 diffrent files (3 files got a lot of functions in them and 1 has class). Do we have any option to import whole scripts (with all the functions, classes, variables) on top of my main file so they will appear in my enviroment?

for exmaple in file "foo.R" i have a function "food = function(...)" so i do smth like

from foo.R import food

result <- 2*food(a,b,c)

or

from foo.R import *
result <- 2*foo.food(a,b,c)

like in python?

2 Answers2

1

I think you should take a look at the combination of here + source. Basically, what you can do is the following:

library(here)
source(here::here('R', 'file_that_contains_a_lot_of_functions.R'))

In that way, you will get all the functions from file_that_contains_a_lot_of_functions.R in the GlobalEnviroment make it easy to work with them.

PS1: the 'R' above is because I am assuming you downloaded a mirror of the library from Github, and you are taking the functions from the R folder.

PS2: it also assumed that you generated a project at the level of the main folder of the package. What I also do is to generate an extra folder my_folder where I store everything that I create to do not disturb the workflow of the original package.

0

use the command source() and put in the file to run - then you will have access to all objects within.

source("path/to/your/file.R")

alex_danielssen
  • 1,839
  • 1
  • 8
  • 19