From timo at timogrossenbacher.ch  Wed Jul 13 09:13:08 2016
From: timo at timogrossenbacher.ch (timo at timogrossenbacher.ch)
Date: Wed, 13 Jul 2016 09:13:08 +0200 (CEST)
Subject: [Rd] [R] Forking and adapting an R package
In-Reply-To: <a53bf014-6081-cbf4-96e0-5826b71be8e6@gmail.com>
References: <1880276709.61511.1468322926354.JavaMail.open-xchange@ox11.mail.hostpoint.internal>
	<a53bf014-6081-cbf4-96e0-5826b71be8e6@gmail.com>
Message-ID: <2030499666.69029.1468393989099.JavaMail.open-xchange@ox11.mail.hostpoint.internal>

> Duncan Murdoch <murdoch.duncan at gmail.com> hat am 12. Juli 2016 um 19:38
> geschrieben:
> 
> On 12/07/2016 7: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?
> 
> This is more of an R-devel question, so I've posted my followup there 
> (as well as a private copy to you).
> 

Okay, I'm now subscribed to this list, too.

> The fact that you've forked the package shouldn't matter. You are 
> working in RStudio, so the way to work with a package is:
> 
> 1. Open the project consisting of your local package.
> 2. In the Build pane, click on "Build and Reload".
> 
This works. devtools::build() though throws the same error with the vignette as
with devtools::check(). See below.

> What "Build and reload" does is to install the package from the source 
> in the project, then restart R and load the installed package.
> 
> Test your code in this new R session. If you're working on a vignette, 
> you can open the vignette, and execute the code chunks one by one.
> 
Ok. But how do I debug the source code of that package? I.e. I want to call a
function from that package from another, external script (that is not part of
that project), and then jump into the function execution and debug it. 
Because when it's built it's no longer "plain source code", or am I completely
wrong with this? Or/and do I have to make the  external script part of the
hexbin project?

> If they all succeed in that context, they still might not when you run 
> checks: it *won't* have your package loaded when it compiles a 
> vignette. You need to put an explicit
> 
> library(hexbin)
> 
This is actually done in the chunk that fails (it fails on the last line here).

library("grid")
library("hexbin")
x <- rnorm(1000)
y <- rnorm(1000)
##-- Hexagon Bins: --
hbin <- hexbin(x,y, xbins = 25)

> in one of the code chunks.
> 
> Duncan Murdoch
> 
> >
> > 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.
> >

>



[Rd] [R] Forking and adapting an R package
timo at timogrossenbacher.ch