Reputation: 1029
Goal: I downloaded an R-package "ABC" from CRAN and would like to achieve two things:
ex_fct
of that R-package.nw_fct
to that R-package.and these adjustments shall be permanent.
Situation: There are good sources that explain the first aspect on how to edit/change/overwrite an existing function of an R-package here, but trying to follow this approach seems not to work for adding new functions to a package.
Question: Hence, I wish to add the function nw_fct
as a hidden function in that package so that it can be called via ABC:::nw_fct
. How can this be done? Is there a way to simultaneously address both aspects?
Upvotes: 2
Views: 1563
Reputation: 1029
Solution: The following steps worked for me (on a Mac) to simultaneously solve both aspects:
ex_fct
. I opened this file in R-Studio adjusted the ex_fct
function as desired and added the nw_fct
also to that file (because the ex_fct
and nw_fct
functions are related) and saved it under the same name, i.e. as "algo-A.R". As a result, I now have an updated package folder that contains my updated version of the "algo-A.R" file.build
function of the devtools
package to create a single bundled ".tar" file (say file "ABC_new.tar") from this updated package folder. Specifically, one may simply use: build(pkg= "path1/ABC_1.1-2", path= "~path2/ABC_new.tar", manual=F, binary=F)
, where path1
navigates to the place of the updated package folder and path2
says where the bundled package shall be stored. Notice: As I did this on a new machine, this step did not work immediately but required to first install e.g. TeXLive, Java Applications as well as several packages required by the ABC package (simply follow R's error commands).install.packages(“~path2/ABC_new.tar", repos = NULL, type=“source”)
Should you wish to undo these changes and have the original package again, you may simply remove the package and re-install the original one from CRAN.
Upvotes: 2