It sounds like the issue is due to your package's autogenerated RcppExports files (RcppExports.cpp and RcppExports.R) not being available when your friend installs the package from GitHub. Here's how you can fix this:
Include the RcppExports files in your GitHub repository:
-
Check .gitignore: Ensure that your .gitignore file is not excluding the RcppExports.cpp and RcppExports.R files. Sometimes patterns like *.cpp or *.R could inadvertently exclude these files.
-
Generate RcppExports files: Before committing your code to GitHub, run:
Rcpp::compileAttributes()
This will generate or update the RcppExports.cpp and RcppExports.R files based on your exported C++ functions.
-
Commit and Push: Add the RcppExports.cpp and RcppExports.R files to your Git repository:
git add RcppExports.cpp RcppExports.R
git commit -m "Include RcppExports files"
git push
-
Update NAMESPACE (if necessary): Ensure that your NAMESPACE file correctly exports the functions. You can regenerate it using:
devtools::document()
Then commit and push the updated NAMESPACE file.
Why this works:
When someone installs your package from GitHub, they get the files as they are in the repository. If the RcppExports files aren't included, the package won't have the necessary code to link your C++ functions to R, resulting in the "function not found" error.
By including these generated files, you ensure that anyone installing your package—even from source—has all the necessary components for it to work correctly.
Alternative for your friend:
If, for some reason, you prefer not to include the RcppExports files in your repository, instruct your friend to manually generate them after installing the package:
-
Install the package without building vignettes:
devtools::install_github("yourusername/yourpackage", build_vignettes = FALSE)
-
Navigate to the package directory and run:
Rcpp::compileAttributes("path/to/your/package")
Then reinstall the package.
However, the preferred solution is to include the RcppExports files in your repository to make installation seamless for all users.
Summary:
- Include
RcppExports.cpp and RcppExports.R in your GitHub repository.
- Ensure they are not ignored by
.gitignore.
- Regenerate and commit these files whenever you change your exported C++ functions.
By ensuring these files are part of your package source, others can install and use your package without issues.
Note: This is a common issue when developing R packages with C++ code using Rcpp. Including the generated files ensures your package is portable and can be used by others without requiring them to manually generate these files.
Answer: Because your package’s generated RcppExports files aren’t included, your friend’s install lacks the necessary code—include RcppExports.cpp and RcppExports.R in your GitHub repo so they’re present when others install the package.