[R] Forking and adapting an R package

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Thu Jul 14 16:31:49 CEST 2016


1) Although it can be as easy as this, when you are dealing with packages the complications of namespaces may prevent your modified version of the function now in the global namespace from being used by other functions in the package. That is, you may have to redefine all of the interrelated functions in the global namespace to get the desired behaviour. I do agree that for self study or a one-off task working in the global environment can serve just fine, but reading "Advanced R" by Hadley Wickham may help you understand some of these mysteries if you have multiple functions working together. 

2) I seem to recall that compiling without vignettes is typical for development. Not that failing to compile with vignettes is okay (there could be a bug in the package or even in R), but you might get further down the road if you disable vignettes for now. Read the Writing R Extensions document and/or your the documentation for your development environment (RStudio).

3) Reading the Posting Guide would have informed the OP that there is an R-package-dev mailing list where this topic might be better raised now (though it used to belong in R-help).
-- 
Sent from my phone. Please excuse my brevity.

On July 14, 2016 1:33:45 AM PDT, BONACHE Adrien via R-help <r-help at r-project.org> wrote:
>Hi Timo,
>To perform the first point, you just have to write the function name in
>R without using parentheses and arguments after it. You will see the
>code of the function. Copy and Paste it on notepad, change the name of
>the function in the notepad, then change what you want to change in
>your function. After it copy and paste the function in R. Use it!
>Best wishes with your code!
>Adrien.
>
>      De : "timo at timogrossenbacher.ch" <timo at timogrossenbacher.ch>
> À : "Adams, Jean" <jvadams at usgs.gov>; r-help <r-help at r-project.org> 
> Envoyé le : Jeudi 14 juillet 2016 8h40
> Objet : Re: [R] Forking and adapting an R package
>   
>On Jul 13, 2016 15:02, Adams, Jean wrote:
>>
>> Timo,
>>
>> A couple of thoughts ...
>>
>> First, could you achieve what you want by simply modifying (your own
>copies
>> of) a function or two from the hexbin package, without having to
>modify the
>> entire package?  This might give you fewer tripping points.
>>
>
>Good point, how would I do this? Just copy-paste the original source
>and
>redeclare/overwrite the functions within my use case script?
>
>> Second, right after you forked the package (so that you have a copy
>on your
>> own space on GitHub) and before you modified anything ... were you
>able to
>> install and use the package from there successfully?
>>>
>>> library("devtools")
>>> devtools::install_github("grssnbchr/hexbin")
>>> library(hexbin)
>>
>
>I basically forked and cloned it, and then ran devtools::check()
>without
>modifying anything, and it threw an error when compiling the vignette.
>Also
>building fails this way. It seems to work fine when installed with
>devtools::install_github(). Weird, I know.
>
>Anyhow, the question with (modifying and) debugging a (forked) package
>in order
>to understand how it works still stands, maybe there's something in
>Hadley's
>book that I oversaw.
>
>Timo
>
>>
>> Jean
>>
>> On Tue, Jul 12, 2016 at 6:28 AM, <timo at timogrossenbacher.ch> wrote:
>>>
>>> Hello.
>>>
>>> I'm trying to adapt the package “hexbin” to suit my needs. This is
>the first
>>> time I do this. I've read a bit through Hadley's “R packages”, but
>now I'm
>>> pretty lost (from a workflow point of view). I am using RStudio and
>Hadley's
>>> devtools.
>>>
>>> So I forked the repo I want to adapt:
>https://github.com/grssnbchr/hexbin
>>>  and
>>> cloned it using RStudio (I created a new project). What I basically
>want to
>>> do
>>> is adapt the package slightly and use the adapted source on my use
>case (an
>>> Rmd
>>> file in another location) - ideally, I would call the respective
>function
>>> (hexbin::grid.hexagons) in the Rmd and the source code of “hexbin”
>would be
>>> called and debugged (just for understanding what the package
>“hexbin”
>>> actually
>>> does in that case, I do not have to build it yet, or even publish
>it). What
>>> is
>>> the workflow for this?
>>>
>>> Also, I tried running devtools::check() and it already fails there:
>>> R version 3.2.5 (2016-04-14) -- "Very, Very Secure Dishes"
>>>
>>> Platform: x86_64-pc-linux-gnu (64-bit)
>>>
>>> > devtools::check()
>>> Updating hexbin documentation
>>> Loading hexbin
>>> Creating a generic function for ‘plot’ from package ‘graphics’ in
>package
>>> ‘hexbin’
>>> Creating a generic function for ‘summary’ from package ‘base’ in
>package
>>> ‘hexbin’
>>> Setting env vars
>>>
>-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>>> CFLAGS : -Wall -pedantic
>>> CXXFLAGS: -Wall -pedantic
>>> Building hexbin
>>>
>------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>>> '/usr/lib/R/bin/R' --no-site-file --no-environ --no-save
>--no-restore --quiet
>>> CMD build '/home/tgrossen/R/hexbin' --no-resave-data --no-manual
>>>
>>> * checking for file ‘/home/tgrossen/R/hexbin/DESCRIPTION’ ... OK
>>> * preparing ‘hexbin’:
>>> * checking DESCRIPTION meta-information ... OK
>>> * cleaning src
>>> * installing the package to build vignettes
>>> * creating vignettes ... ERROR
>>>
>>> Error: processing vignette 'hexagon_binning.Rnw' failed with
>diagnostics:
>>>  chunk 1 (label = comphexsq)
>>> Error in eval(expr, envir, enclos) : could not find function
>“hexbin”
>>> Execution halted
>>> Error: Command failed (1)
>>>
>>> As you can see, I am very much lost. I googled for "adapt R package
>and
>>> debug"
>>> and so forth but couldn't find any tutorial or anything.
>>>
>>> Thanks,
>>>
>>> Timo
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
>
>  
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list