Skip to content
Prev 46267 / 63461 Next

Problem with distributing data in package.

Hi Brian,

Thanks for the response. My original request contained the code that I
have placed in a file in the data directory, though this had been
removed in Barry's response. I have copied the original email below.
While I did mention "When I build the package" in that email, I did
not, however, state that I did this using the command:

R CMD build <package-name>

I apologise for being remiss. For my own education, is there anything
else I should have provided as part of a reproducible example?

I did not know there was an option --no-resave-data (I had not thought
to look at `R CMD build --help`, there is no mention of it in
R-exts.pdf and my ability to use Google is clearly lacking... though I
did try that), but it appears to be exactly what I need - Thankyou!

Kind Regards,
Simon Knapp




---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------
start of original email
---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------
Hi List,

I am building a package for a client to help them create and perform
analyses against netcdf files which contain 'a temporal stack' of
grids.

For my examples and test cases, I create an example dataset in code
(as this is a lot more space efficient than providing raw data). The
code creates a netcdf file in tempdir() and an object of class 'ncdf'
in the global namespace. I have placed the code in a .R file in the
data directory of my package and 'load' it with a call to data().

My problem
-----------------
When I build the package, the code gets executed during the build
process, the netcdf file gets created in tempdir() and the 'ncdf'
object gets saved to a .rda file in the package... which is not very
useful, since when I call data() the object gets loaded but the netcdf
file is not present (further, the 'ncdf' object includes the path to
the netcdf file - in my tempdir()).

My question
------------------
Is there a way to circumvent the creation of the .rda file and build
the package such that it contains the .R files instead (I note that
this is what appears to happen with a binary build for windows)? If
not, then is there another 'R-ish' way to achieve a similar result?

Just in case it is useful, I have included the code I use to build the
netcdf file and 'ncdf' object below.

Thanks in advance,
Simon Knapp


#--------------------------R code starts here--------------------------
# create a netcdf file holding a 'temporal stack'
combined.ncdf <- with(new.env(), {
    require(ncdf)
    nLat <- 7
    nLon <- 8
    nTime <- 9
    missing.val <- -999
    filename <- file.path(tempdir(), 'combined_d6fg4s64s6g4l.nc')
    lat.dim <- dim.def.ncdf('lat', 'degrees', 1:nLat)
    lon.dim <- dim.def.ncdf('lon', 'degrees', 1:nLon)
    time.dim <- dim.def.ncdf("time", "days since 1970-01-01",
as.integer(1:nTime), unlim=T)
    var.def <- var.def.ncdf('Data', 'mm', list(lon.dim, lat.dim,
time.dim), missing.val, prec='single')
    nc <- create.ncdf(filename, var.def)
    for(i in 1:nLon)
        for(j in 1:nLat)
            for(k in 1:nTime)
                put.var.ncdf(nc, var.def, i + j*10 + k*100, c(i, j,
k), rep(1, 3))
    close.ncdf(nc) # seems to be required.
    open.ncdf(filename)
})

---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------
end of original email
---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------





On Sun, Jul 21, 2013 at 3:25 AM, Prof Brian Ripley
<ripley at stats.ox.ac.uk> wrote: