Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating internal functions (can't be called from console) in R

Tags:

r

I'm working on an R package where I have an overarching function that generates some files, we'll call it main(...) and it exists in its own file main.R. Now main calls other functions like helper1(...) and helper2(...) which are found in helper1.R and helper2.R. Is it possible to make it so that main can call the helper functions, but the user cannot call directly the helper functions? I have them spread out in different files due to the stark differences in their purpose. Is the solution to put them all under one file main.R?

like image 338
TomNash Avatar asked Jan 29 '16 18:01

TomNash


1 Answers

Read R packages by Hadley Wickham.

What you want is should be the default behaviour for packages: you have exported and non-exported functions. Unless you explicitly declare a function as exported, it is invisible to the outside and only usable by other functions inside the package.

So you don’t need to do anything for the helper functions. You do, however, need to mark the main function as exported.

like image 111
Konrad Rudolph Avatar answered Oct 19 '22 05:10

Konrad Rudolph