Skip to content

wrap the C function for speed #5

@japhir

Description

@japhir

Stephen Meyers suggested a simple way of using

system2("./snvec.x", "-1000", "1", "0", "/path/to/cachedir", "full-ZB18a.dat")

He did warn me that this will not pass CRAN checks however.

This is awesome!

After quickly asking on #R, people there agreed that first doing it this way and just publishing it on github would be a nice start, then later on I could rewrite the C source code so that the R functions can use .C() directly.

I've built this locally and it works great! Will see when/if I can put it in a separate branch on github.

I've added a valid (new default) output = "source" option. If it cannot find the executable it will fall back to the slow implementation. Had to rewrite some of the tests but was pretty smooth!

Following what aitap told me on #R and https://cran.r-project.org/doc/manuals/R-exts.html#Package-subdirectories

  • Added the raw c source code to the src/ directory
  • Added src/Makefile that builds it to snvec.x, makes it executable, then moves it to inst/
  • Added src/install.libs.R that autmatically should copy the prebuilt files to the correct folder
  • use system.file() to find where the newly compiled snvec.x is located
  • Change snvec.R so it calls that executable with system2().

Also tried if Windows will play nice with it via devtools::check_win_devel(). It doesn't seem to source the Makefile.

Up next:

  • Makefile shouldn't have to move the file around, because that changes depending on the OS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions