Albert EINstEIN
2009-Jul-27 11:27 UTC
[R] create dataset permanently in package (i.e. default or our own package)
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. -- View this message in context: http://www.nabble.com/create-dataset-permanently-in-package-%28i.e.-default-or-our-own-package%29-tp24679076p24679076.html Sent from the R help mailing list archive at Nabble.com.
Steve Lianoglou
2009-Jul-27 15:59 UTC
[R] create dataset permanently in package (i.e. default or our own package)
Mr. Einstein, On Jul 27, 2009, at 7:27 AM, 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.I'm not sure if this is exactly what you're asking, but this is the question I'm going to answer: How can I include/bundle a dataset with a package that I am developing? Answer: Simply save your dataset into an *.rda/*.RData file and place it in the data directory of the package you're developing. So, for example, let's say you've done so and the name of your file is "TheoryOfRelativity.rda".Once the package is installed (and loaded(?)), you can load the datafile it by calling: data(TheoryOfRelativity) === I'm not sure that saving your own data file into *some random* package's data directory is a good idea, or what you're asking, but you can do that, too. Just specify the package you need to load it from. For example, if I saved 'TheoryOfRelativity.rda' in the 'nnet' package's data directory (for some weird reason). You can load it like so: load(TheoryOfRelativity, package='nnet') HTH, -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact
cls59
2009-Jul-27 21:04 UTC
[R] create dataset permanently in package (i.e. default or our own package)
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.