[R] create dataset permanently in package (i.e. default or our own package)

cls59 chuck at sharpsteen.net
Mon Jul 27 23:04:16 CEST 2009



Albert EINstEIN wrote:
> 
> Hi,
> actually while opening R console and R commander we see some packages like
> car and datasets. in this packages we have default datasets are available.
> example: women and prestige like that. now i created a sales dataset
> importing from excel, xml or text file. now i want to store that dataset
> permanently  in any one of the package like i mentioned above (car or
> datasets). now i closed my R session. after some time i opened R console
> and R commander. Now I will not create again sales dataset.While clicking
> any one of package that sales dataset should be found. 
> if possible please give me the code it will be very helpful for us.
> 
> Thanks in advance.
> 
> 

The steps you need to follow are:

1. Open a new R session.

2. Create your 'sales' dataset and any other datasets you want to preserve.
Make sure these are the only objects in your workspace- i.e. they are the
only names that come up when you use ls().

3. Create a new package using package.skeleton('myPackage')

This will create a new folder called myPackage that contains a folder called
data. Inside data will be a .rda file for your sales dataset and any other
datasets you had in your environment at the time package.sekeleton was run.

Now you need to install your package. This can be done by:

system('R CMD INSTALL myPackage')

Or from the command line:

R CMD INSTALL myPackage

Note that if you are using Windows, you will need to install Duncan
Murdoch's Rtools package located at:

http://www.murdoch-sutherland.com/Rtools/

If the installer asks anything about modifying your PATH, allow it to do so.

Once the package has been installed, you can load your dataset using:

library(myPackage)
data(sales)

If you want to add additional data sets, save them to individual .rda files
using:

save('myFirstNewDataset',file='myFirstNewDataset.rda')
save('mySecondNewDataset',file='mySecondNewDataset.rda')

Then move the .rda files to the data folder inside the myPackage folder and
re-run R CMD INSTALL

Hope that helps!

-Charlie

-----
Charlie Sharpsteen
Undergraduate
Environmental Resources Engineering
Humboldt State University
-- 
View this message in context: http://www.nabble.com/create-dataset-permanently-in-package-%28i.e.-default-or-our-own-package%29-tp24679076p24688214.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list