I have a function in an R package that I want to make completely inaccessible to a user of the package. I know that I can not export the function, but even then the function would still be accessible to the user by doing packageName:::hiddenFunction
. Is there any way to make this function completely inaccessible?
Asked
Active
Viewed 74 times
2

mosk915
- 696
- 1
- 7
- 16
-
1What is the purpose of this? Your intention may make some methods work or not... – Gregor Thomas Sep 29 '20 at 20:48
-
For example, you could set a "password", `foo <- function(pw){if(missing(pw) | pw != "ABC") stop("No!"); return(2)}`. Or you could take the approach of `dplyr::n()`, which I believe checks the calling environment. – Gregor Thomas Sep 29 '20 at 20:49
-
3"inaccessible" as in "they can't *run* it" or "inaccessible" as in "they can't look at the code"? The answer to (2) is almost certainly "no". – Ben Bolker Sep 29 '20 at 20:56
-
1Regardless, R code is distributed with a package. I don't think there's any way to make it so a user couldn't look at your code and use it or modify it for their use. See the old [Protect/encrypt R code for distribution](https://stackoverflow.com/q/25283022/903061) question for reference. – Gregor Thomas Sep 29 '20 at 20:56
-
“Inaccessible” as in they can’t look at the code. However, I would be interested in a solution where they can’t run it, even if they can see the code. – mosk915 Sep 29 '20 at 21:06