r modify and rebuild package
Asked Answered
A

2

26

I'm trying to use the SemiMarkov package and I want to change one small line of code in there. I've done some digging via:

getAnywhere("semiMarkov")

& I've identified that I want to change this line:

hessian <- diag(ginv(hessian(V, solution)))

to try something like:

hessian <- diag(ginv(pracma::hessian(V, solution)))

How do I go about this? Do I need to rebuild the package from scratch, and if so do I need rTools etc for this, or is there a simple-ish workaround (I'm a relevant R novice)? I've done some searching online and can't find anything obvious. Any ideas/pointers gratefully appreciated.

Anisette answered 14/1, 2016 at 21:44 Comment(0)
C
25

Linux environment

Starting with downloading the package source from CRAN.

Download and extract the source:

wget https://cran.r-project.org/src/contrib/SemiMarkov_1.4.2.tar.gz
tar -xvzf SemiMarkov_1.4.2.tar.gz

This should result in a directory named SemiMarkov. Open up the source (cd SemiMarkov), and modify as necessary.

Next, build the changes:

cd ..
R CMD build SemiMarkov/

This will result in a new archive file named SemiMarkov_1.4.2.tar.gz.

Lastly, install your modified archive:

R CMD INSTALL SemiMarkov_1.4.2.tar.gz

Windows environment

I'm less familiar with the Windows platform. *nix tooling is available in Cygwin, but it's painful. Instead, as Josh O'Brien points out, you should follow the Windows-specific instructions in the R Installation and Administration manual.

Chemisorb answered 14/1, 2016 at 21:44 Comment(3)
@Anisette The general advice here (that you should compile a modified version of the package) is great. As a long-time Windows user myself, though, who has written and modified many packages, I would very strongly advise you against trying to do this with Cygwin.Ramsey
Instead, you'll should carefully follow the Windows-specific instructions in the R Installation and Administration manual. (The linked appendix notes, "This appendix contains a lot of prescriptive comments. They are here as a result of bitter experience." I'd suggest you take that warning seriously, if you want a relatively pain-free experience!) Once you've got the appropriate toolset in place, installing the modified package will be as simple as doing devtools::install("SemiMarkov").Ramsey
Great pionts @JoshO'Brien :) Hope you don't mind, I updated my answer with your content. Feel free to edit it!Chemisorb
H
41

If you'd like to simply test out the effect of that change in an interactive R session, you can do so using trace(). Here's how:

  1. Type trace("semiMarkov", edit=TRUE)
  2. In the text editor that that launches, edit the line of interest.
  3. Save the modified file.
  4. Close the text editor
  5. Back in R, use the modified function.
Hebner answered 14/1, 2016 at 22:6 Comment(2)
Many thanks, this also really helpful for a quick way of testing and very easy!Anisette
I didnt know about trace, but it is extremely helpful, thanks!Furbelow
C
25

Linux environment

Starting with downloading the package source from CRAN.

Download and extract the source:

wget https://cran.r-project.org/src/contrib/SemiMarkov_1.4.2.tar.gz
tar -xvzf SemiMarkov_1.4.2.tar.gz

This should result in a directory named SemiMarkov. Open up the source (cd SemiMarkov), and modify as necessary.

Next, build the changes:

cd ..
R CMD build SemiMarkov/

This will result in a new archive file named SemiMarkov_1.4.2.tar.gz.

Lastly, install your modified archive:

R CMD INSTALL SemiMarkov_1.4.2.tar.gz

Windows environment

I'm less familiar with the Windows platform. *nix tooling is available in Cygwin, but it's painful. Instead, as Josh O'Brien points out, you should follow the Windows-specific instructions in the R Installation and Administration manual.

Chemisorb answered 14/1, 2016 at 21:44 Comment(3)
@Anisette The general advice here (that you should compile a modified version of the package) is great. As a long-time Windows user myself, though, who has written and modified many packages, I would very strongly advise you against trying to do this with Cygwin.Ramsey
Instead, you'll should carefully follow the Windows-specific instructions in the R Installation and Administration manual. (The linked appendix notes, "This appendix contains a lot of prescriptive comments. They are here as a result of bitter experience." I'd suggest you take that warning seriously, if you want a relatively pain-free experience!) Once you've got the appropriate toolset in place, installing the modified package will be as simple as doing devtools::install("SemiMarkov").Ramsey
Great pionts @JoshO'Brien :) Hope you don't mind, I updated my answer with your content. Feel free to edit it!Chemisorb

© 2022 - 2024 — McMap. All rights reserved.