Profiling an installed R package with source line numbers?
I would like to profile functions in an installed R package ( data.table
) using Rprof()
c line.profiling=TRUE
. Typically an installed package is byte-compiled, and line numbers are not available for byte-compiled packages. The usual instructions for profiling strings with Rprof()
require the use of source()
or eval(parse())
that the attributes be present srcref
.
How can I load data.table so that the row numbers are active? My naive attempts to download the package with first library(data.table)
and then source('data.table.R')
fail because some of the compiled C functions are not found when I try to use the package, apparently because it library()
uses a different namespace. Maybe there is some way source()
to enter the correct namespace?
Alternatively, perhaps I can create a modified version data.table
that has not been byte-compiled and then load it in a way that preserves the line numbers? What changes would I have to make, and how would I load it? I started by installing ByteCompile: FALSE
and then tried it R CMD INSTALL -l ~/R/lib --build data.table
, but it still looks like bytes being compiled.
I really want to do this job and will pursue any suggestions. I am running R 3.2.1 on Linux, have full control over the machine, and can install whatever is required.
Edit:
A more complete description of the problem I was trying to solve (and a solution for it) is given here: https://github.com/Rdatatable/data.table/issues/1249
I ended up doing what Joshua suggested: recompile the package with "KeepSource: TRUE" in the DESCRIPTION. For my purposes, I also found "ByteCompile: FALSE" useful, although this may not apply in general. I also changed the version number to see that I am using my modified version.
Then I installed to a different location with "R CMD INSTALL data.table -l ~ / R / lib" and loaded with "library (data.table, lib = '~ / R / lib)". When used with the patches referenced in the link, I got the line numbers from the appropriations as needed. But if anyone knows a solution that doesn't require recompilation, I'm sure others will appreciate if you share.
source to share
You should be able to get line numbers even if the package is compiled. But as it says in ?Rprof
(emphasis mine):
Individual applications will be written to the profile of the magazine, if
line.profiling
-TRUE
, and if the executable code analyzed references to sources . Seeparse
source links for discussion. By default, operator locations are not shown insummaryRprof
, but see the help page for enabling mapping.
This means that you need to install KeepSource: TRUE
either to a file DESCRIPTION
or via an argument --with-keep.source
to R CMD INSTALL
.
source to share