How to edit and debug R library sources - r

I've included a library called blotter in my R script which has a bug in it. Is there an easy way for me to edit the source to try and debug the issue?

Look up the trace and browser functions, they are the basic tools in R for debugging. Say you want to edit the source of function foo, then saying
trace("foo",edit=TRUE)
will open up the source of foo in the editor for you to change. However, this is for interactive debugging; the source files in the packages are not changed. So once you have found the bug, you need to change the package source files for the change to be permanent.

Such a feature is implemented in the development version of R (Jul 16, 2010):
A new facility has been added to r-devel for experimenting by authors of
packages.
The idea is to insert modified code from the package source into the
running package without re-installing. So one can change, test, change,
etc in a quick loop.
The mechanism is to evaluate some files of source code, returning an
environment object which is a snapshot of the code. From this
environment, functions and methods can be inserted into the environment
of the package in the current session. The insertion uses the trace()
mechanism, so the original code can be restored.
The one-step version is:
insertSource("mySourceFile.R", package = "myPackage", functions = "foo")
See this post for further details: Inserting and testing revised functions in a package

Your question of Is there an easy way for me to edit the source to try and debug the issue? has the obvious answer: Use the source, Luke!
blotter is a package on R-Forge from where you can get blotter sources here. That is the standard way of looking at Open Source and possibly helping it along with a bug fix.

Related

Why does R crash when adding DESeq2 as dependency to R package?

I'm writing an R package using devtools and roxygen2. Note that this is my first time making a package, so maybe I am missing something important.
I want to add a dependency, the package, DESeq2. I have tried to do this in a number of ways, but believe the right way is to add the following to my DESCRIPTIONS file.
Depends:
DESeq2
If I add this, when I build and reload I get a fatal error. When running in RStudio it just gives a "Fatal Error" dialog and restarts the application. It appears to build, but when it does, library(myPackage), it crashes immediately.
If I remove the Depends section from the DESCRIPTIONS file it builds and loads fine. What's more, if I include a different package, for example, ggplot2, then it builds and loads fine as well.
What about a package would cause it to fail to load as a dependency and completely crash? Is there another way to require it or is there any way to dig deeper into the cause?
Thanks very much in advance.

How to edit R library source files in-place

This a follow-up to How to edit and debug R library sources. I'm wondering if there's an easy way to edit an R library source file and cause the edited file to be loaded by library without reinstalling the code. I'm asking this in the context of a library that I'm developing and am looking for an easy way to incrementally edit and test my code. I know about source and other ways of loading code into an R session, but I want to test scripts that do the usual library thing.
Thanks!
It sounds like you're developing a packages. If that's the case then using the devtools package is probably what you want to do. The load_all() function will systematically reload all of your code so you can make changes and test everything out.

change functionality of R package

I am trying to get my head around an R package. I installed it from github, worked with it. Also downloaded the ZIP-File from github which contains the files of the package. For experimental reasons I added some code in the files I downloaded.
Now I would like to see whether my changes do what they are supposed to do.
Is there an easy way to do this?
I would like to avoid creating a whole new package and installing it.
Or is this the only way?
I had the idea to directly change the code in the package I installed (location received from the function path.package()). Unfortunately I cannot access the code there.
The tutorials I read were also not helpful.
I would be thankful for any advice.

Modifying R package maintained by someone else

There's a semantic error in a function of an R package written by someone else. I contacted that person which is mentioned in the 'DESCRIPTION' file of the package over email, and there is no response. But, I need to move forward with my project.
Is it possible for me to correct that error and check-in the change of that project ? If that's not possible, should I write my own version of the function with the correction and call it? What would be the best way to move forward ? Thanks.
The only way to update that particular package on CRAN is to contact the package maintainer. But you can just obtain the package's sources (you can fork it from CRAN readonly mirror on a github), fix it your way and source changed .R files after loading the package (or build entire package from sources if your fixes are in C++ code). I've done it many times. If your changes may be useful to the community, you're encouraged to create your own package.

Where to report bugs of R packages?

Some packages do have a reference to bug reporting system, others do not. Where should I report package bugs then? Is there any default bug reporting system for packages which don't have their own?
I found https://bugs.r-project.org/bugzilla3/ but when I look at the components it seems more like for the R core. I also tried bug.report(package = "runjags"), but it tried to start mail program which is not very useful.
If in doubt, send an email to the package maintainer.
packageDescription("thepackagename", fields = "Maintainer")
(This is what bug.report does.)

Resources