Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrap the C function for speed #5

Open
1 task
japhir opened this issue Mar 21, 2024 · 0 comments
Open
1 task

wrap the C function for speed #5

japhir opened this issue Mar 21, 2024 · 0 comments

Comments

@japhir
Copy link
Owner

japhir commented Mar 21, 2024

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant