Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
856 views
in Technique[技术] by (71.8m points)

r - functions not loaded from homebuilt package

I'm learning to build my own packages using RStudio. The current .tar.gz for the package (named SteenSubsSpec) is here. Currently the Build & Reload command appears to build & Roxygen-ize the package successfully. However, the functions do not appear to be loaded into memory, despite the fact Build & Reload successfully updates the documentation. What am I doing wrong?

Build & Reload give the following output:

==> roxygenize('.', roclets=c('rd'))
  • checking for changes ... DONE

==> R CMD build SteenSubsSpec

* checking for file ‘SteenSubsSpec/DESCRIPTION’ ... OK
* preparing ‘SteenSubsSpec’:
* checking DESCRIPTION meta-information ... OK
* excluding invalid files
Subdirectory 'R' contains invalid file names:
  ‘2013_08_30_report-concordance.tex’ ‘2013_08_30_report.Rnw’
  ‘2013_08_30_report.log’ ‘2013_08_30_report.pdf’
  ‘2013_08_30_report.synctex.gz’ ‘2013_08_30_report.tex’
* checking for LF line-endings in source and make files
* checking for empty or unneeded directories
Removed empty directory ‘SteenSubsSpec/inst’
* building ‘SteenSubsSpec_1.0.tar.gz’

Source package written to ~/Dropbox/[my directory]

This updates the documentation: ?write_paper() displays the current documentation as expected. However

require(SteenSubsSpec) 
write_paper() 

gives Error: could not find function "write_paper"

Some things that seem to be correct:

  • All function files are in the R directory, and have the same name as their definition (e.g /R/write_paper.R defines write_paper() <- function {...
  • The DESCRIPTION file contains the names of all the relevant function files: Collate: ... 'write_paper.R

How can I troubleshoot this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Most likely, the functions are not exported to the NAMESPACE file (which you state is currently empty).

In RStudio, under "build tools" in "project options", make sure that "Generate documentation with roxygen" is checked. Then, click on "configure". Make sure that "Use roxygen to generate NAMESPACE file" is also checked.

In your R function files, add an @export yourfunctionname in there (or, technically, an #' @export yourfunctionname), and when you build and reload, your NAMESPACE file should be updated and your functions should no longer be invisible.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...