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
?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With