Submitting a package to CRAN: .tar.gz file - r

I have a package I am ready to submit to CRAN (everything checks out). However, in the spot where it says Choose File, I am unsure what file to choose, as it says it requires a .tar.gz file, which I gather is some kind of compressed file?
Do I need to compress everything into a .tar.gz file? If so, how?
If not, I have a .Rproj file, and various files like namespace and description and license, so it is unclear to me which file to submit.
I apologize if this is a simple question, this is my first package to be submitted.

You have two options here. Use R's command line command:
> R CMD build /path/to/package/directory
Or use devtools::build from within R:
R> devtools::build( "path/to/package/directory" )
Both result in a tar.gz file on your local file system. The name will look like: mypackage_[Version].tar.gz
It is this file that you load to CRAN.

Related

Unpacking compressed package file after R package installation

I'd like to include a large data file in my R package. This file is located in the inst directory, and it is compressed. My goal is to yield a smaller package size on our local repository while eliminating decompression at attachment time.
Every time my package is attached, it must decompress the file which takes a few seconds.
Is there a way to decompress this file permanently upon installation of my package?
Don't save in inst/ and use usethis to save data
I'd strongly recommend using usethis::use_data to save data in a R package setting. With use_data(), it saves to data/. You can also set the compress method. For your purpose, I'd suggest method = "xz" (see the save documentation on compression).
The other thing to do is set LazyData: false in the DESCRIPTION file, then when you want to access the data, use data("dataname", package = "yourpackage") to load it.
See the chapter on Data in the R Packages book. It helps clarify many things.

R: instructions for unbundling and using a packrat snapshot

I used packrat (v 0.4.8.-1) to to create a snapshot and bundle of the R package dependencies that go along with the corresponding R code. I want to provide the R code and packrat bundle to others to make the work I am doing (including the R environment) fully reproducible.
I tested unbundling using a different computer from the one I used to write R code and create the bundle. I opened an R code file in R studio, and called library(packrat) to load packrat (also v 0.4.8-1). I then called packrat::unbundle(bundle = "directory", where = "directory"), which unbundled successfully. But subsequently calling packrat::restore() gave me the error "This project has not yet been packified. Run 'packrat::init()' to init packrat". It seems like init() should not be necessary because I am not trying to create a new snapshot, but rather utilize the one in the bundle. The packrat page (https://rstudio.github.io/packrat/) and CRAN provide very little documentation about unbundling to help troubleshoot this, or that I could point users of my code to for instructions (who likely will be familiar with R, but may not have used packrat).
So, can someone please provide clear step-by-step instructions for how users of a bundled snapshot should unbundle, and then use that saved snapshot to run a R code file?
After some experimenting, I found an approach that seems to have worked so far.
I have provided users with three files:
-tar.gz (packrat bundle file)
-unbundle.R (R code file that includes a library statement to load
the packrat library, and the unbundle command for the tar.gz file)
-unbundle_readme.txt
The readme file includes instructions similar to those below, and so far users have been able to run R code using the package dependencies. The readme file tells users about requirements (R, R studio, packrat, R package development prerequisites (Rtools for Windows, XCode for Mac)), and includes output of sessionInfo() to document R package versions that the R code should use after instructions are followed. In the example below 'code_folder' refers to a folder within the tar.gz file that contains R. code and associated input files.
Example unbundle instructions:
Step 1
Save, but do not expand/unzip, the tar file to a directory.
Problems with accessing the saved package dependencies
are more likely when a program other than R or R studio
is used to unbundle the tar file.
If the tar file has already been expanded, re-save the
tar file to a new directory, which should not be a the same
directory as the expanded tar file, or a subdirectory of
the expanded tar file.
Step 2
Save unbundle.R in the same directory as the tar file
Step 3
Open unbundle.R using R studio
Step 4
Execute unbundle.R
(This will create a subfolder ‘code_folder’.
Please note that this step may take 5-15 minutes to run.)
Step 5
Close R studio
Step 6
Navigate to the subfolder ‘cold_folder’
Step 7
Open a R script using R studio
(The package library should correspond to that listed below.
This will indicate R studio is accessing the saved package
dependencies.)
Step 8
Execute the R code, which will utilize the project package library.
After the package library has been loaded using the above
steps, it is not necessary to re-load the package library for each
script. R studio will continue to access the package dependencies
for each script you open within the R studio session. If you
subsequently close R-studio, and then open scripts from within
the unbundle directory, R studio should still access the
dependencies without requiring re-loading of the saved package
snapshot.

How can I read gzip compressed grib files in R?

I am trying to open MUlti-sensor precipitation data from eumetsat in R. I can get these data only using GZIP compression method and data format type is GRIB. When I download data I get tar file.
How can I open these data in R?
I tried to use code
> untar("1098496-1of1")
but got error message
Error in gzfile(path.expand(tarfile), "rb") : cannot open the connection
In addition: Warning message:
In gzfile(path.expand(tarfile), "rb") :
cannot open compressed file '1098496-1of1', probable reason 'No such file or directory'
but I when I use next code:
> dir.create("rainfalldataeumetstatR")
> getwd()
[1] "C:/Users/st/Documents"
> untar("1098496-1of1.tar")
> untar("1098496-1of1.tar", files="rainfalldataeumetstatR")
> list.files("rainfalldataeumetstatR")
I don't get some files in my directory and get answer:
character(0)
May be that error appears because files in tar zip are gz archives?
I, too, have grappled with opening GRIB files in R. You have several problems and can tackle them one by one.
For the untar and gzip issues, work from the command line. I don't know how the tar package is built/packaged from Eumetsat; does it create a directory and put all the data files in that directory? In that case, put the tarball in a top-level data directory and then
tar xvf tar_file_name
cd (to the directory that was just created)
gunzip *.gz
Note down the full path name of the files you will want to open for later use.
Are the files in GRIB1 or GRIB2? If in GRIB1, you need to install wgrib. If in GRIB2, you need to install wgrib2. Both are available from NCEP.
You can download them from:
http://www.cpc.ncep.noaa.gov/products/wesley/
In R, 3.1 and later, you install the rNOMADS package 2.0.1 and later.
NOAA National Operational Model Archive and Distribution System (NOMADS) distributes global grid data in GRIB format (currently in GRIB2).
rNOMADS helps you open GRIB1 and GRIB2 data in R by calling wgrib or wgrib2 to decode the binary GRIB data and pipe it (in csv format) for R to read in.
Open up R, load up rNOMADS, and then call the ReadGrib routine using the full path name of your data file in "data_file_name". This is not the way described in the rNOMADS documentation, but it works.
Installing wgrib and wgrib2 is the only hard part and it may not even be that hard, depending on your system. I'm writing tutorials on how to install wgrib, wgrib2 and use rNOMADS with local data files. When I am done, they will be posted here:
http://rda.ucar.edu/datasets/ds083.2/#!software
Now for some bad news:
You need to open each file sequentially. But, you can extract and save the subfields you need, and then read in the next datafile, overwriting the large data structure into which you read the previous file. If that is too much of a PITA, have you considered using the GRADS tool for displaying GRIB data?
There is no native way to read grib files into R. Use wgrib or wgrib2 depending on whether your file is in grib or grib2 format. I am the package manager for rNOMADS - and trust me, we tried to figure out a simple R way, and ended up dropping it. Maybe the folks at NCEP will do it someday, but it's out of our skill range.
Personally I untar my files using cygwin also because the wgrib package in cygwin will allow you to get an inventory file so you can tell R what data is contained in each layer. Under the assumption the data is grib1 r can read it directly. Grib2 requires wgrib2 on your machine, RNomads is working on that challenge.
Alright I recently found a great website that shows how to install wgrib so that it can run in R in conjunction with rNOMADS.
https://bovineaerospace.wordpress.com/2015/04/26/how-to-install-rnomads-with-grib-file-support-on-windows/#comments

creating package

i am creating a package in R language, everything is running properly, but when i run R CMD check , it shows an error message while running examples.. i.e.
"can't open the file." "No such file or directory"
actually my function needs a PubMed text file containing abstracts from the PubMed, i have placed my text file in every sub-directory of my package, but its not working. showing same error again and again.
so please suggest me the right way how to put a text file in a package which can be used by examples to run properly.
i will be very thankful to you.
Usually you put such data in the /inst folder. E.g.:
<packageRoot>/inst/pubmed/myfile
After the package is build you can access the content of this folder from within the package like this:
system.file( "pubmed/myfile", package="<package>" )
See for more information http://cran.r-project.org/doc/manuals/r-release/R-exts.pdf (1.1.5 Data in packages).
I suggest you to use devtools and roxygen2 packages. Basically, you just need to prepare description and .R files.
see more details in this brilliant answer :devtools roxygen package creation and rd documentation

R: using package by unzipping it instead of installing it

I am trying to use a package which can not run at such in window Rgui. The website of the package suggests for unzip and use the function
http://mouse.cs.ucla.edu/emma/install.html
But I did not way to find where I can find the function that I can enter in my R console and use it.
Help appreciated
EDITS:
RGUi that comes with windows distribution
Packaged useed is: emma, can be downloaded from the above website
And the all-R, mouse-free version (I was almost there Roman!):
download.file("http://mouse.cs.ucla.edu/emma/emma_1.1.2.tar.gz",
destfile=paste(getwd(),"/emma/emma_1.1.2.tar.gz",sep=""))
untar(paste(getwd(),"/emma/emma_1.1.2.tar.gz",sep=""), compressed = "gzip")
source(paste(getwd(),"/emma/R/emma.R",sep=""))
wherein a new directory (emma/) will be created in your present working directory.
You can download the .tar.gz file and use untar function. I've moved the file in question to my Q drive in folder emma and ran the following command. The result was extracted to a folder called emma under my working directory.
untar("q:/emma/emma_1.1.2.tar.gz", compressed = "gzip")
After you've done that, you can source the .R files (see comments under your question).

Resources