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

Automatically register C functions #50

Closed
hadley opened this issue Oct 9, 2018 · 3 comments
Closed

Automatically register C functions #50

hadley opened this issue Oct 9, 2018 · 3 comments

Comments

@hadley
Copy link
Member

hadley commented Oct 9, 2018

If package has src/, doesn't use Rcpp, and has either no src/init.c or one previously created by pkgbuild:

  • Run tools::package_native_routine_registration_skeleton(".", character_only = FALSE)
  • Replace FIXME comment and with standard generated by comment
  • Save to src/init.c
  • Warn if namespace does not contain useDynLib(package, .registration = TRUE)
@jeroen
Copy link
Member

jeroen commented Oct 9, 2018

It would be nice if it would also be possible to add custom calls into the generated R_init_xyz() code because I often need to make a call that initiates an external library in there.

One way would be if package autho would put the custom init code inside R_init_xyz_custom() and then the generated code should contain a call to R_init_xyz_custom() if this function exists. Or something along those lines.

An example of a package that needs this: https://github.com/cran/av/blob/master/src/init.c#L23

@jeroen
Copy link
Member

jeroen commented Oct 9, 2018

Perhaps the other way around is easier: The generated function could be renamed from R_init_xyz to R_init_xyz_symbols which can then be called from the the R_init_xyz() function defined by the pkg author.

Optionally, if no R_init_xyz exists, it could also be autogenerated to simply be:

void R_init_xyz(DllInfo *dll) {
  R_init_xyz_symbols(dll);
}

Package authors can tweak this R_init_xyz with custom code that does not get overwritten when the autogenerated R_init_xyz_symbols code is updated..

@hadley
Copy link
Member Author

hadley commented Oct 9, 2018

Another approach suggested by @jeroen

You could also wrap the call inside an #ifdef CALL_USER_INIT so that the package author can enable it in Makevars using CPPFLAGS=-D_CALL_USER_INIT

jimhester added a commit that referenced this issue Oct 15, 2018
pkgbuild now supports generation of the native routine registration for
C code. The way this works is it uses
tools::package_native_routines_registration_skeleton() to generate the
registrations, than inserts them in `src/init.c` between pkgdown
specific comments.

The rest of the file is passed through unchanged, so if you need to have
custom init code or additional includes you can do so just by adding it
to the same file, only the code
within the comments will be altered when the registration is updated.

Fixes #50
jimhester added a commit that referenced this issue Oct 15, 2018
pkgbuild now supports generation of the native routine registration for
C code. The way this works is it uses
tools::package_native_routines_registration_skeleton() to generate the
registrations, than inserts them in `src/init.c` between pkgdown
specific comments.

The rest of the file is passed through unchanged, so if you need to have
custom init code or additional includes you can do so just by adding it
to the same file, only the code
within the comments will be altered when the registration is updated.

Fixes #50
jimhester added a commit that referenced this issue Oct 16, 2018
pkgbuild now supports generation of the native routine registration for
C code. The way this works is it uses
tools::package_native_routines_registration_skeleton() to generate the
registrations, than inserts them in `src/init.c` between pkgdown
specific comments.

The rest of the file is passed through unchanged, so if you need to have
custom init code or additional includes you can do so just by adding it
to the same file, only the code
within the comments will be altered when the registration is updated.

Fixes #50
jimhester added a commit that referenced this issue Oct 16, 2018
pkgbuild now supports generation of the native routine registration for
C code. The way this works is it uses
tools::package_native_routines_registration_skeleton() to generate the
registrations, than inserts them in `src/init.c` between pkgdown
specific comments.

The rest of the file is passed through unchanged, so if you need to have
custom init code or additional includes you can do so just by adding it
to the same file, only the code
within the comments will be altered when the registration is updated.

Fixes #50
jimhester added a commit that referenced this issue Oct 16, 2018
pkgbuild now supports generation of the native routine registration for
C code. The way this works is it uses
tools::package_native_routines_registration_skeleton() to generate the
registrations, than inserts them in `src/init.c` between pkgdown
specific comments.

The rest of the file is passed through unchanged, so if you need to have
custom init code or additional includes you can do so just by adding it
to the same file, only the code
within the comments will be altered when the registration is updated.

Fixes #50
jimhester added a commit that referenced this issue Oct 16, 2018
pkgbuild now supports generation of the native routine registration for
C code. The way this works is it uses
tools::package_native_routines_registration_skeleton() to generate the
registrations, than inserts them in `src/init.c` between pkgdown
specific comments.

The rest of the file is passed through unchanged, so if you need to have
custom init code or additional includes you can do so just by adding it
to the same file, only the code
within the comments will be altered when the registration is updated.

Fixes #50
jimhester added a commit that referenced this issue Oct 16, 2018
pkgbuild now supports generation of the native routine registration for
C code. The way this works is it uses
tools::package_native_routines_registration_skeleton() to generate the
registrations, than inserts them in `src/init.c` between pkgdown
specific comments.

The rest of the file is passed through unchanged, so if you need to have
custom init code or additional includes you can do so just by adding it
to the same file, only the code
within the comments will be altered when the registration is updated.

Fixes #50
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

2 participants