Skip to content

[Bioc-devel] Packaging a medium/large project

2 messages · ushi, Julian Gehring

#
Hey list,

i am about to package a fairly large project. Unfortunately, the code
quality is suboptimal - it uses a lot of source() to jump between source
files:

  data <- ...

  # Do something with data
  source("R/process_data.r", local=T)

  # Do something with the results
  source("R/process_results.r", local=T)

  # Do something like this many times
  ...

Whats the best way to package something like this? My idea was to write
a slim wrapper:

  something.run <- function(data) {
    source("R/run.r")
  }

The problem now is that source() can't find the files, when executed
inside the package. What is best practice here (apart from a rewrite)?

Cheers, ushi
#
Hi Ushi,

For an R package, you would like to get rid of the 'source' calls
completely.  You would want to design your code such that different
tasks are represented as different functions.  If you have all these
functions in the 'R' directory of your package, you can access them
easily and do not have to worry about scoping.  You can find more
details at http://cran.r-project.org/doc/manuals/R-exts.html.

Best wishes
Julian
On 16/04/14 13:57, ushi wrote: