[R] export R-data to VisIt

Katharine Mullen kate at few.vu.nl
Fri Oct 19 18:27:26 CEST 2007

Below is an example R -> netCDF -> R for rows of a dataframe that are
numeric vectors --note however that your dataframe includes character
vectors.  I can't look into that case at the moment - maybe it's easy to
solve, or maybe you have to do some hashing.

## begin ex.

dat <- matrix(rnorm(20),10,2)

c1 <- dim.def.ncdf( "c1", "c1units", 1:nrow(dat) )
c2 <- dim.def.ncdf( "c2", "c2units", 1:nrow(dat) )

x1 <- var.def.ncdf(name="v1", units="c1units",dim = c1, missval=0)
x2 <- var.def.ncdf(name="v2", units="c2units",dim = c2, missval=0)

## for some reason, when vars is the vector c(x1,x2) this does't work
## it may be a bug; get around my adding other vars later
ncnew <- create.ncdf(filename="file.cdf", vars = x1)
ncnew <- var.add.ncdf(ncnew, x2)

put.var.ncdf(ncnew, "v1", dat[,1])
put.var.ncdf(ncnew, "v2", dat[,2])

ofile <- open.ncdf("file.cdf")

c_x1 <- get.var.ncdf(ofile, "v1")
c_x2 <- get.var.ncdf(ofile, "v2")

> Peter,

what a quick response!

But unfortunately, yes I tried the ncdf package, I looked at the examples,
but after 2 hours trying and many, many errors,  I gave up.....

----- Original Message -----
From: "Peter Dalgaard" <P.Dalgaard at biostat.ku.dk>
To: "Bart Joosen" <Bartjoosen at hotmail.com>
Cc: <r-help at stat.math.ethz.ch>
Sent: Friday, October 19, 2007 4:56 PM
Subject: Re: [R] export R-data to VisIt

Bart Joosen wrote:
> Hello,
> Is there anyone porting R data to VisIt (http://www.llnl.gov/visit/)?
> Altough VisIt accepts 5 dozen of data formats, I can't get my data into
> VisIt.
> I currently ran a simulation which gave me a data frame, which I wanted to
> import into VisIt to further explore the dataframe.
> Let's say I have a data frame as follows:
> dat <- data.frame(cbind(  1,   1:10),X3= sample(LETTERS[1:3], 10,
> repl=TRUE))
> My currently data export is write.table(dat,"C:/filename.csv")
> But I can't import this kind of data in Visit.
> An option is to export my dataframe as a .CDF file, but I couldn't get the
> right output of my dataframe with netcdf.
> So how do I put my dataframe in a netCDF format, or is there anyone who
> knows the easiest way to transport my data to VisIt?
Have you tried the ncdf package?

   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907

R-help at r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list