Troublesome package creating - r

I have some problems with creating package, can you please spot my mistake?
I followed instruction below :
1.Create functions I want in my package
2.Open new project -> R package
3.Create as many R documentation as many functions I implemented, and then put them into man folder
4.Press Ctr+Shift+B to install package.
The warning I'm facing is
Warning: C:/Program Files/R/R-3.6.3/library/mypackage/man/myfun2.Rd:62: All text must be in a section
I search internet about solution to that problem but I found only involved instructions containing other approach. Is there possibility how to fix this ? Or other approach with using other packages is crucial (as roxygen).
Thanks in advance

You should not write the manual pages yourself. You should use roxygen code to write the manual elements in your function R files, then use devtools::document() to generate the manual pages. See here for examples: https://keithmcnulty.github.io/r_package_training/index.html#1

Related

How I can ease out myself of .Rd file when I am developing an R package

I am developing my own R package using R studio 1.2.1335. Within R folder of my package, I have function r2.R for which I did not build r2.rd file in man folder. When I am checking packgae using command R CMD ..., then I got the following warning message.
checking for missing documentation entries ... WARNING
Undocumented code objects:
'r2'
All user-level objects in a package should have documentation entries.
See chapter 'Writing R documentation files' in the 'Writing R
How I can solve this isue ?
Thanks,
Mahdi.
There are several solutions.
Don't export r2. If it's an internal function, it doesn't need documentation.
Write man/r2.Rd. Running prompt(r2) will give you a skeleton version of the file which you can edit into a real one.
Learn roxygen2 syntax, and put that into your .R source code. It can generate the r2.Rd file.
Personally, I generally do 1 or 2, but lots of people seem to think 3 is preferable. Your choice.

URL '/help/library/<package>/r/html/00Index.html' not found when using `devtools::load_all()`

I am using devtools::load_all as a workflow to iteratively make a package. However, I cannot seem to be able to view the package documentation using ? or help(package=package_name) until I install the package. The error I get is:
No documentation for ‘function’ in specified packages and libraries
and
URL '/help/library//r/html/00Index.html'
any suggestions on how to resolve this?
Thanks!
I guess the help(package=package_name) do nothing than open (in case of Windows) this file for you:
C:\Users\YourName\Documents\R\win-library\4.1\package_name\html\00Index.html
devtools::load_all make your latest functions available to you for testing without installing the package (i.e. the html file was not updated, and masked because it was belonged to the old version of your own package). To view your latest documentation (i.e. make a new version html), you can devtools::document() and check your package working directory \man\Functions_name.rd, OR, devtools::install() and help(package=package_name)
Just restarting r session solved my problem.

Unable to generate help files from R package

I have created a package in R. It is all fully documented and written according to R package guidelines. I have used devtools to generate documentation.
document("/home/rstudio/EndoMineR/")
However when I try to use ?EndoMineR I get the error:
No documentation for ‘EndoMineR’ in specified packages and libraries:
you could try ‘??EndoMineR’
How can I create the help files for my package? What am I likely to be missing?
As additional information, when I click the package name in R studio I get the help files but not if I try ?EndoMineR. Also the .Rd files in the man directory (which I think is what devtools::document() generates) seem to be updating just fine. I assume the ?EndoMiner accesses the man files so I'm not sure why this folder is not accessible (it is top level)

How do I fix errors from R CMD check --as-cran to get my R package accepted on CRAN?

Executive Summary
I need assistance to fix the errors as I attempt to create a manual for a new R package. I have created an R package on my computer that I would like to distribute. At the moment, the package is available as a repository on GitHub (http://www.github.com/greenspb/poker), but I want to contribute it to the Comprehensive R Archive Network. I wrote the code years ago, but never shared it out of fear. This is my first repository on GitHub and my first submission to CRAN. I have researched how to get my package on CRAN by reading a blog post at http://kbroman.org/pkg_primer/pages/cran.html . I am stuck on step 1:
"Run R CMD check --as-cran and eliminate all problems. If there are any errors or warnings, your package will not be accepted at CRAN. And even a “Note” will likely disqualify you. So figure out what all of those errors, warnings, and notes mean and then revise your package so that they are no longer issued."
The report generated by "Run R CMD check --as-cran poker" for my "poker" package ( available as a repository on GitHub ) contains errors. My concern is failure to make the LaTeX manual.
Resolved Issues
I used roxygen2 comment tags in the .R file in the project's R folder. roxygen2::document() successfully translated \cr in a comment tag into a new line in the LaTeX file, however it unsuccessfully translated every empty \tab in a comment tag into {} [empty curly parentheses] in the LaTeX file. This happened in dozens and dozens of instances. The \tabular environment was used in an attempt to preserve formatting. I was able to clean up LaTeX errors whenever "There was no line here to end" by searching for {} and replacing appropriate instances with \\{}.
Unresolved Issues
I have no idea how to solve the LaTeX error "Rd2.tex: File Ended while scanning definition of \LT#xxiii", although I believe \LT stands for long table. I am only able to make pdf manuals of several individual functions using R CMD Rd2pdf on the .rd documentation files.
My code is documented using roxygenize tags. When I execute the Run R CMD check --as-cran command, R encounters errors and warnings and fails to make the pdf for the entire package. I need assistance to fix the errors in the report. I want to get my package on CRAN.
See Also
Question on r-package-devel#r-project.org mailing list.
Removing comments on the local variables was the answer to fixing the errors ( replying to #Dason). Thank you.

showing vignettes link upon building and reloading an R package

I have created a vigentte folder for an R package I am developing by running the code devtools::use_vignette("my-vignette"). I am using Rmarkdown and knitr packages.
When I build & reload the package, I don't get a hyperlink for the title of the Rmarkdown file (which contains the long-form documentation of the package) in the documentation page of the package. I do get hyperlinks for the DESCRIPTION file of the package as well as the help pages of the documented functions but not the hyperlink that should direct people to the Rmarkdown document. I am wondering why and what should I do to get a hperlink for the long-form documentation of the package in a similar way that I get it for the help pages for the functions used in the package?
Daragh,
Can you provide more detail on the error you are seeing? If the code is posted on github or you have a specific error then we may be able to help further - if not then the best advice I can give is to check out Hadley Wickam's "R Packages" book online - it is a great reference:
http://r-pkgs.had.co.nz/
that will at least give you a good sense of how to build the vignettes.
http://r-pkgs.had.co.nz/vignettes.html
From the online book by Hadley Wickham referenced above...
CRAN notes
Note that since you build vignettes locally, CRAN only receives the html/pdf and the source code. However, CRAN does not re-build the vignette. It only checks that the code is runnable (by running it). This means that any packages used by the vignette must be declared in the DESCRIPTION. But this also means that you can use Rmarkdown (which uses pandoc) even though CRAN doesn’t have pandoc installed.
Common problems:
The vignette builds interactively, but when checking, it fails with an error about a missing package that you know is installed. This means that you’ve forgotten to declare that dependency in the DESCRIPTION (usually it should go in Suggests).
Everything works interactively, but the vignette doesn’t show up after you’ve installed the package. One of the following may have occurred. First, because RStudio’s “build and reload” doesn’t build vignettes, you may need to run devtools::install() instead. Next check:
The directory is called vignettes/ and not vignette/.
Check that you haven’t inadvertently excluded the vignettes with .Rbuildignore
Ensure you have the necessary vignette metadata.
If you use error = TRUE, you must use purl = FALSE.
You’ll need to watch the file size. If you include a lot of graphics, it’s easy to create a very large file. There are no hard and fast rules, but if you have a very large vignette be prepared to either justify the file size, or to make it smaller.

Resources