i am creating a package in R language, everything is running properly, but when i run R CMD check , it shows an error message while running examples.. i.e.
"can't open the file." "No such file or directory"
actually my function needs a PubMed text file containing abstracts from the PubMed, i have placed my text file in every sub-directory of my package, but its not working. showing same error again and again.
so please suggest me the right way how to put a text file in a package which can be used by examples to run properly.
i will be very thankful to you.
Usually you put such data in the /inst folder. E.g.:
<packageRoot>/inst/pubmed/myfile
After the package is build you can access the content of this folder from within the package like this:
system.file( "pubmed/myfile", package="<package>" )
See for more information http://cran.r-project.org/doc/manuals/r-release/R-exts.pdf (1.1.5 Data in packages).
I suggest you to use devtools and roxygen2 packages. Basically, you just need to prepare description and .R files.
see more details in this brilliant answer :devtools roxygen package creation and rd documentation
Related
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)
I made an R package for personal use, but the way I load it is by individual files. Such as:
source("../compr/R/compr.R")
source("../compr/R/error_df.R")
source("../compr/R/rmse.R")
I would like to load the entire package, which is called compr, as I would other libraries.
If you are using RStudio, I would suggest creating a project and setting it to your compr directory. After that you will be able to use devtools::load_all() to load your package directly.
If you don't want to do this, or you don't use RStudio devtools::load_all('path/to/compr') will also work.
P.S. compr directory needs to be the root of the package i.e. the place where your DESCRIPTION file is.
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.
I am planing to do all my R scripts in the same package in order to move it easily between my friends.
What I have done is created an R packages using R studio and the following files have been automatically generated:
projectName.Rproj
DESCRIPTION
man
NAMESPACE
R
Read-and-delete-me
I created a new R script and I save it in R folder. Now I want to add a new R script that uses functions that have been defined in the first script.
I created this new script and I tried to use on of the functions that are located in the other script. I got error that the function is not defined.
What I tried to solve the problem
I used the source command in the beginning of the new script like this:
source('something.R')
I got error message that something.R doesn't exist.
What is the solution please to include functions that exist in a different scripts ** but in the same packages**?
NoteI don't want to use relative paths because I want the package to be as portable as possible
Thanks a lot
You appear to misunderstand how package works: by having a file with a function in the R/ directory, it is already visible to other code in the package.
If you want to make it available to other packages, you can control this via the NAMESPACE file. All this is well-documented in Writing R Extensions which comes with your copy of R, and a number of additional books and tutorials you could peruse.
I'm trying to write a vignette for a package in R. I've been following a tutorial from Vanderbilt University as well as the offical documentation.
I made a .Rnw Sweave file and put it into a subdirectory inst/doc inside my package. Inside the same subdirectory inst/doc, I put a folder example containing some example text files. My package has a function myparser(path) that I want to demonstrate in the vignette; myparser(path) creates several data frames by reading in the text files inside the folder with absolute path name path.
Then I checked the package using R CMD CHECK, and got this error:
* checking running R code from vignettes ...
‘mypackage-vignette.Rnw’ using ‘UTF-8’ ... failed
ERROR
Errors in running code in vignettes:
when running code in ‘mypackage-vignette.Rnw’
...
> library(mypackage)
Loading required package: ggplot2
> myparser("/example/")
Warning in file(file, "rt") :
cannot open file '/example/': No such file or directory
When sourcing ‘mypackage-vignette.R’:
Error: cannot open the connection
Execution halted
I see my attempt to use a relative pathway to the folder didn't work (probably should have been obvious to me), but I'm still not sure how to fix this situation. I don't want to replace path with an absolute pathway to the folder on my computer, because then the vignette's code won't be reproducible on other people's computers.
How can I include the example files in the package so that the vignette's code is reproducible? Am I even approaching this problem in the right way?
(Sorry this question isn't itself more reproducible!)
You can use system.file('doc', 'example', package = 'mypackage') to refer to that directory, because R will install the package before building vignettes, as you can see when you run R CMD build mypackage.