I have a couple of text files that I want to include for examples in my documentation of data cleaning, however, when I include the text files in my 'data' file, I get an error from R CMD check
saying that the package "cannot be installed", whereas if I don't include it, the package can be installed but it gives me an error saying that it the examples do not work because it can't find the text files (of course). Is there a way around this?
Asked
Active
Viewed 1,329 times
8

user2407894
- 427
- 1
- 4
- 10
-
Try putting the files in an "inst" folder instead. – A5C1D2H2I1M1N2O1R2T1 Jun 24 '13 at 15:40
-
Put them in the `inst` folder as I've done here: https://github.com/trinker/reports/tree/master/inst – Tyler Rinker Jun 24 '13 at 15:40
-
can you give us some more information about these "text" files that you're trying to include in your package. – A5C1D2H2I1M1N2O1R2T1 Jun 24 '13 at 16:23
-
they are tab-seperated tables of weather data that I am trying to use as an example of data cleaning, @AnandaMahto. – user2407894 Jun 24 '13 at 17:37
-
@TylerRinker can you access them from the examples in your `man` files? – user2407894 Jun 24 '13 at 17:43
-
1@user2407894 Yes. You can use something like: `system.file("extdata/docs", package = "reports")` – Tyler Rinker Jun 24 '13 at 18:17
1 Answers
10
Building on @Tyler Rinker's comment, I think the proper place to include miscellaneous files is to include them in a inst/
directory in the package directory. From Section 5.1 of http://cran.r-project.org/doc/contrib/Leisch-CreatingPackages.pdf, we get:
'inst/' for miscellaneous other stuff. The contents of this directory are completely copied to the installed version of a package.
This means that you would be able to get the text file using code like the following:
readLines(file = paste0(path.package("yourpackage"), "/your_text_file.txt"))

Alex
- 15,186
- 15
- 73
- 127
-
better use `system.file` than `path.package` : This tells more: https://stackoverflow.com/questions/13463103/inst-and-extdata-folders-in-r-packaging – moodymudskipper Sep 23 '21 at 14:31