[R] R packages and assess to data in packages

Sharpie chuck at sharpsteen.net
Sat Dec 5 23:54:27 CET 2009



Tariq Perwez wrote:
> 
> Hi Everyone,
> 
> I have two very basic questions and would appreciate your help.
> 1. I would like to see/access the data that comes with a given R package
> by
> using a function like read.table(). For example, I just installed car
> package from CRAN. I know that somewhere within the package, there is
> Duncan.txt file. 
> 

This is not necessarily true.  Most packages distribute data sets in the
.rda format.  Text files are usually only distributed if the package
implements some method of parsing them, such as the example .xml files in
the XML package.



Tariq Perwez wrote:
> 
> I would not only like to look at it from file browser (or
> using ls command in shell)  but also to access it as:
> 
>> Duncan <- read.table("path/to/data/Duncan.txt", header = T)
> 
> I can certainly use:
> 
>> data(Duncan)
> 
> and
> 
>> attach(Duncan)
> 
> after loading the package car. However, I would like to see all the data
> that come with a package as separate files. Where are these files located?
> I
> installed the car package under Mac OSX  under the user level (if this
> detail is important). However, I do use R under Ubuntu linux also and
> general solution to this problem will be great. 
> 

The system.file() command provides a platform-independent method for
recovering the path to files distributed in packages.  For example, to list
all files in the "data" folder of the car package:

  system.file( 'data', package = 'car' )

To get the path to the .rda file containing all the datasets:

  system.file( 'data', 'Rdata.rda', package = 'car' )


Tariq Perwez wrote:
> 
> I even downloaded the car binaries and unpacked the zipped file on desktop
> but I just see .rda files
> within the data folder; there are no .txt files anywhere.  I do see
> Duncan.rda file (I believe this contains the Duncan.txt data). How can I
> access the data files from such package, say using a text editor??
> 

Package datasets are usually only distributed as binary .Rda files.  If you
want to view them using a text editor you will have to translate them to a
plain text format-- something like load() followed by write.csv().



Tariq Perwez wrote:
> 
> 2. What is the safest/preferred place to install an R package that I want
> to
> delete/remove once I do not need it. Sometimes, I just need to install a
> package from a book's website so that I can work on the exercises etc but
> do
> not need the package permanently hanging around. Removing such a package
> and
> all the associated files etc would be nice.
> 
> I would appreciate any help and comments on my questions. Regards,
> 
> Tariq
> 

Just install it normally.  You can remove it by running:

  R CMD REMOVE packageName

>From the command line.

Hope this helps!

-Charlie

-- 
View this message in context: http://n4.nabble.com/R-packages-and-assess-to-data-in-packages-tp949415p949439.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list