Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to include text files in the 'data' subdirectory of an R package

Tags:

r

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?

like image 687
user2407894 Avatar asked Jun 24 '13 15:06

user2407894


People also ask

Which command can be used to import text files in R?

Importing using fread() It is part of the data. table package, which you will need to install. The fread() command is simpler to use because it tries to guess the format of the data in the file.

Can R read TXT files?

R can read data from a variety of file formats—for example, files created as text, or in Excel, SPSS or Stata. We will mainly be reading files in text format . txt or . csv (comma-separated, usually created in Excel).

Do R packages contain data?

R packages contain code, data, and documentation in a standardised collection format that can be installed by users of R, typically via a centralised software repository such as CRAN (the Comprehensive R Archive Network).

What does Extdata mean in R?

extdata: Extra data used to calculate ID numbers in Yassai et al.'s nomenclature.


1 Answers

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"))
like image 178
Alex Avatar answered Sep 29 '22 17:09

Alex