[R] plot one levelplot over another

2018-11-19 Thread Waichler, Scott R
Hi, I am using levelplot() to plot a primary response surface, z1.  I wish to 
write a custom panel function that will let me plot another surface z2 = f(x,y) 
over z1.  The second surface z2 is either NA or 1, and at locations where z2 = 
1, I will use a color with low alpha to let the the z1 surface show through.  
How can I do this?

Regards,
Scott Waichler
Pacific Northwest National Laboratory
Richland, WA USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] seq() problem with chron

2018-09-06 Thread Waichler, Scott R
Hi, 

I encountered the problem below where the last value in the chron vector 
created with seq() should have a time of 15:30, but instead has 15:15.  What 
causes this and how can I make sure that the last value in the chron vector is 
the same as the "to" value in seq()?

library(chron)
dt1 <- chron("02/20/13", "00:00:00")
dt2 <- chron("07/03/18", "15:30:00")
dt <- seq(from=dt1, to=dt2, by=1/(24*4))
dt[length(dt)]
#[1] (07/03/18 15:15:00)

Thanks,
Scott Waichler
Pacific Northwest National Laboratory
scott.waich...@pnnl.gov

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] ggplot's aes_ doesn't work as expected for x=factor()

2017-08-13 Thread Waichler, Scott R
I'm learning how to use ggplot in a programming approach where I supply 
variable names on the fly.  Using aes_ doesn't work as I expected when x = 
factor(x).  Is this a bug or am I not understanding something?

# toy dataset
df <- data.frame(LogicalVar = c(FALSE, TRUE, FALSE, TRUE, FALSE, TRUE),
 Var1 = c(0.01, 0.01, 1, 1, 30, 30),
 pct1 = c(12, 88, 60, 40, 93, 7),
 Var2 = c(2, 2, 4, 4, 8, 8),
 pct2 = c(43, 57, 10, 90, 50, 50)
)
varnames <- names(df)
# using aes()--this works
ggplot(df, aes(x=factor(Var1), y=pct1, fill=LogicalVar)) + 
geom_bar(stat="identity")  # works

# using aes_() works in this instance
ggplot(df, aes_(x=as.name(varnames[2]), y=as.name(varnames[3]), 
fill=as.name(varnames[1]))) + geom_bar(stat="identity")  # works

# it doesn't work here, where only change is using x=factor()
ggplot(df, aes_(x=factor(as.name(varnames[2])), y=as.name(varnames[3]), 
fill=as.name(varnames[1]))) + geom_bar(stat="identity") # doesn't work
Error in unique.default(x, nmax = nmax) :
  unique() applies only to vectors

# aes_ does work if I make the x variable a factor ahead of time
df2 <- df
df2$Var1 <- as.factor(df2$Var1)
ggplot(df2, aes_(x=as.name(varnames[2]), y=as.name(varnames[3]), 
fill=as.name(varnames[1]))) + geom_bar(stat="identity") # works

Regards,
Scott Waichler
Pacific Northwest National Laboratory
Richland, WA, USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] plot3D color ramp not working as expected

2017-06-29 Thread Waichler, Scott R
Hi, I want to use a discrete color ramp with plot3D, and show NA values as 
white (default).  I get unexpected results per the following.

# as in help(slice3D) example:
par(mfrow = c(2,2))
x <- y <- z <- seq(-1, 1, by = 0.1)
grid <- mesh(x, y, z)
colvar <- with(grid, x*exp(-x^2 - y^2 - z^2))
slice3D (x, y, z, colvar = colvar, theta = 60)
#
# use three discrete classes and colors instead of a continuous ramp
slice3D(x, y, z, colvar = colvar, theta = 60,
col = c("blue", "green", "red"), breaks = c(-0.5, -0.1, 0.1, 0.5))
# now set a vertical slice of the cube to NA
colvar[10,,] <- NA
# displays as expected; default NAcol = "white"
slice3D (x, y, z, colvar = colvar, theta = 60) 
# does not display as expected--notice
# the colors shifted down in value, with NA and -0.5 to -0.1 now both white.
slice3D(x, y, z, colvar = colvar, theta = 60,
col = c("blue", "green", "red"),
breaks = c(-0.5, -0.1, 0.1, 0.5))

Please help.  Thanks,
Scott

Scott Waichler, PhD
Pacific Northwest National Laboratory
scott.waich...@pnnl.gov
Richland, Washington, USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] customizing color key with plot3D

2017-06-21 Thread Waichler, Scott R
Karline,

Thank you for your help.  I discovered that in addition to including clim, I 
needed to omit breaks.  This code uses one of your other examples as a starting 
point and works as intended:

persp3D(z = volcano, zlim = c(-60, 200), phi = 20,
colkey = list(length = 0.2, width = 0.4, shift = 0.15,
cex.axis = 0.8, cex.clab = 0.85), lighting = TRUE, lphi = 90,
clab = c("","height","m"), bty = "f", plot = FALSE)
elev.classes <- matrix(findInterval(volcano, vec = seq(50, 200, by=50)), 
nrow=nrow(volcano), ncol=ncol(volcano))
class.colors <- c("red", "blue", "green")
# add as image with own color key, at bottom
image3D(z = -60, colvar = elev.classes, add = TRUE,
col = class.colors, #breaks = seq(0.5, 3.5, by=1),
clim=c(1,3), 
colkey = list(length = 0.2, width = 0.4, shift = -0.15,
  cex.axis = 0.8, cex.clab = 0.85, addlines=TRUE, 
tick=FALSE, 
  at = c(1.33, 2, 2.66), labels=paste("Class", 1:3)),
clab = c("","Elev Classes"), plot = TRUE)

Your package plot3D is a huge help to me.  Previously I had to use a completely 
different software, VisIt, to do these kinds of composite plots.  R is my 
preferred tool and it is great to finally be able to do these at "home".

Thanks,
Scott Waichler
scott.waich...@pnnl.gov
Pacific Northwest National Laboratory
Richland, Washington, USA

> -Original Message-----
> From: Karline Soetaert [mailto:karline.soeta...@nioz.nl]
> Sent: Wednesday, June 21, 2017 4:16 AM
> To: Waichler, Scott R
> Subject: RE: customizing color key with plot3D
> 
> There is an example in the colkey help file:
> 
> example(colkey)
> 
> will show it ( working on the iris dataset)
> 
> I think the basic thing is that you can use "at"  to position the labels but 
> then
> you also have to specify clim , i.e. "at = c(1.33, 2, 2.66), clim = 
> c(0.5,3.5), col =
> jetc.col(3)"
> 
> Here is the example:
> 
> with(iris, scatter3D(x = Sepal.Length, y = Sepal.Width,
> z = Petal.Length, colvar = as.integer(Species),
>col = c("orange", "green", "lightblue"), pch = 16, cex = 2,
> clim = c(1, 3), ticktype = "detailed", phi = 20,
> xlab = "Sepal Length", ylab = "Sepal Width",
> zlab = "Petal Length",  main = "iris",
> colkey = list(at = c(1.33, 2, 2.66), side = 1,
>addlines = TRUE, length = 0.5, width = 0.5,
>labels = c("setosa", "versicolor", "virginica") )))
> 
> 
> hope it helps,
> 
> 
> Karline
> 
> -Original Message-
> From: Waichler, Scott R [mailto:scott.waich...@pnnl.gov]
> Sent: woensdag 21 juni 2017 2:01
> To: R. Help <r-help@r-project.org>
> Cc: Karline Soetaert <karline.soeta...@nioz.nl>
> Subject: customizing color key with plot3D
> 
> Hi, I am doing composite plots with the package plot3D.  One of my
> variables is qualitative and indexed to integers, and I would like the legend
> for it to have labels located at the integer values (midpoints), and not at 
> the
> breaks between classes.  In the example below, the Elev Classes legend has
> labels at the breaks and nothing at the midpoints.  How can I show the class
> labels at 1:3, and not the breaks?
> 
> library(plot3D)
> persp3D(z = volcano, zlim = c(-60, 200), phi = 20,
> colkey = list(length = 0.2, width = 0.4, shift = 0.15,
> cex.axis = 0.8, cex.clab = 0.85), lighting = TRUE, lphi = 90,
> clab = c("","height","m"), bty = "f", plot = FALSE) # classify the 
> volcano
> elevations with 3 classes elev.classes <- matrix(findInterval(volcano, vec =
> seq(50, 200, by=50)), nrow=nrow(volcano), ncol=ncol(volcano)) class.colors
> <- c("red", "blue", "green") # add as image with own color key, at bottom
> image3D(z = -60, colvar = elev.classes, add = TRUE,
> col = class.colors, breaks = seq(0.5, 3.5, by=1),
> colkey = list(length = 0.2, width = 0.4, shift = -0.15,
>   cex.axis = 0.8, cex.clab = 0.85, addlines=TRUE, 
> tick=FALSE,
>   at = 1:3, labels=paste("Class", 1:3)),
> clab = c("","Elev Classes"), plot = TRUE)
> 
> Thanks,
> Scott
> 
> Scott Waichler
> Pacific Northwest National Laboratory
> Richland, Washington, USA
> scott.waich...@pnnl.gov

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] customizing color key with plot3D

2017-06-20 Thread Waichler, Scott R
Hi, I am doing composite plots with the package plot3D.  One of my variables is 
qualitative and indexed to integers, and I would like the legend for it to have 
labels located at the integer values (midpoints), and not at the breaks between 
classes.  In the example below, the Elev Classes legend has labels at the 
breaks and nothing at the midpoints.  How can I show the class labels at 1:3, 
and not the breaks?

library(plot3D)
persp3D(z = volcano, zlim = c(-60, 200), phi = 20,
colkey = list(length = 0.2, width = 0.4, shift = 0.15,
cex.axis = 0.8, cex.clab = 0.85), lighting = TRUE, lphi = 90,
clab = c("","height","m"), bty = "f", plot = FALSE)
# classify the volcano elevations with 3 classes
elev.classes <- matrix(findInterval(volcano, vec = seq(50, 200, by=50)), 
nrow=nrow(volcano), ncol=ncol(volcano))
class.colors <- c("red", "blue", "green")
# add as image with own color key, at bottom
image3D(z = -60, colvar = elev.classes, add = TRUE,
col = class.colors, breaks = seq(0.5, 3.5, by=1), 
colkey = list(length = 0.2, width = 0.4, shift = -0.15,
  cex.axis = 0.8, cex.clab = 0.85, addlines=TRUE, 
tick=FALSE, 
  at = 1:3, labels=paste("Class", 1:3)),
clab = c("","Elev Classes"), plot = TRUE)

Thanks,
Scott

Scott Waichler
Pacific Northwest National Laboratory
Richland, Washington, USA
scott.waich...@pnnl.gov

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] how apply.monthly() in package xts works

2017-03-09 Thread Waichler, Scott R
Hi,  

I found that apply.monthly() in xts does not work as I expected in the case of 
a sparse timeseries:

my.dates <- as.Date(c("1992-06-01", "1992-06-24", "1992-06-30", "1993-06-22", 
"1994-06-07", "1995-06-08"))
my.xts <- xts(1:6, my.dates)
start(my.xts)  # "1992-06-24"
end(my.xts)  # "1995-06-08"
apply.monthly(my.xts, mean)
#   [,1]
# 1995-06-08 3.5

The endpoints it chooses are based on looking at the month (June) alone.  I was 
able to get a value for each (month, year) in the timeseries with the following 
use of aggregate():

my.months <- months(my.dates)
my.years <- years(my.dates)
df1 <- data.frame(x = coredata(my.xts), dates = my.dates, months = my.months, 
years = my.years)
df2 <- aggregate(df1[-c(3,4)], df1[c("months", "years")], mean)
xts(df2$x, df2$dates)
#[,1]
# 1992-06-182
# 1993-06-224
# 1994-06-075
# 1995-06-086

Two questions:  
1) Is there a more elegant way to do this? 
2) Shouldn't the xts documentation discuss the problem of sparse data?

Regards,
Scott Waichler
Pacific Northwest National Laboratory
Richland, WA  USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] How to 2d cross sections from a 3d finite element mesh

2015-08-10 Thread Waichler, Scott R
Hi, I have a 3D finite element mesh where each element (cell) is defined by 8 
vertices.  Each element is a regular polyhedron.  The overall domain is a block 
in shape, but its horizontal principal axes are not coincident with x and y 
(i.e. the domain is rotated about the z-axis).  

I want to plot 2D cross sections of discrete and continuous values assigned to 
the elements.  I can think of two ways to go about providing the values to 
plot:  1) Use the cross section plane intersection with the elements to define 
a 2D polygon for each intersected element, and plot each as a polygon, with the 
final product being a mosaic of polygons within the plane of intersection; 2) 
interpolate to a regular grid and then plot that.  

Method 1 seems preferable to plotting discrete variables, while the second 
would be better for contouring a continuous variable.  I know how to do a 3D 
interpolation using Delaunay triangulation, but I wonder if there is a package 
out there to simplify things.  I don't know at all how to go about doing it the 
first way.  Can anyone suggest or point me to existing methods?

Thanks,
Scott Waichler
Pacific Northwest National Laboratory
Richland, WA  USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Can't install rgl: installed package can't be loaded; 'memory not mapped'

2015-08-08 Thread Waichler, Scott R
Hi, I can't install package rgl.  The last lines from the install process  
talking about the error are:

** testing if installed package can be loaded
sh: line 1: 11949 Segmentation fault  
'/files3/R/R-3.2.1_install/lib64/R/bin/R' --no-save --slave 21  
'/tmp/RtmpQCpp6N/file2b115f4f8e1d'

 *** caught segfault ***
address (nil), cause 'memory not mapped'
aborting ...
ERROR: loading failed

I realize this is probably not an R problem, but a Google search turns up 
nothing that helps, and I'm hoping someone here can help anyway.  Below are my 
sessionInfo() output and the contents of the first file generated with R CMD 
check rgl_0.95.1247.tar.gz.

 sessionInfo()
R version 3.2.1 (2015-06-18)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

loaded via a namespace (and not attached):
[1] tools_3.2.1


# R CMD check rgl_0.95.1247.tar.gz
* installing *source* package 'rgl' ...
** package 'rgl' successfully unpacked and MD5 sums checked
checking for gcc... gcc -std=gnu99
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc -std=gnu99 accepts -g... yes
checking for gcc -std=gnu99 option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -std=gnu99 -E
checking for gcc... (cached) gcc -std=gnu99
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc -std=gnu99 accepts -g... (cached) yes
checking for gcc -std=gnu99 option to accept ISO C89... (cached) none needed
checking whether __attribute__((visibility())) is supported... yes
checking whether gcc -std=gnu99 accepts -fvisibility... yes
checking whether  accepts -fvisibility... no
checking for libpng-config... yes
configure: using libpng-config
configure: using libpng dynamic linkage
checking for X... libraries , headers 
checking GL/gl.h usability... yes
checking GL/gl.h presence... yes
checking for GL/gl.h... yes
checking GL/glu.h usability... yes
checking GL/glu.h presence... yes
checking for GL/glu.h... yes
checking for glEnd in -lGL... yes
checking for gluProject in -lGLU... yes
checking for freetype-config... yes
configure: using Freetype and FTGL
configure: creating ./config.status
config.status: creating src/Makevars
** libs
g++ -I/files3/R/R-3.2.1_install/lib64/R/include -DNDEBUG -DHAVE_PNG_H 
-I/usr/include/libpng12 -DHAVE_FREETYPE -Iext/ftgl -I/usr/include/freetype2 
-Iext -I/usr/local/include   -g -O2 -fvisibility=hidden -fpic  -g -O2  -c 
ABCLineSet.cpp -o ABCLineSet.o
g++ -I/files3/R/R-3.2.1_install/lib64/R/include -DNDEBUG -DHAVE_PNG_H 
-I/usr/include/libpng12 -DHAVE_FREETYPE -Iext/ftgl -I/usr/include/freetype2 
-Iext -I/usr/local/include   -g -O2 -fvisibility=hidden -fpic  -g -O2  -c 
BBoxDeco.cpp -o BBoxDeco.o
BBoxDeco.cpp: In member function 'int rgl::AxisInfo::getNticks(float, float)':
BBoxDeco.cpp:239: warning: converting to 'int' from 'float'
g++ -I/files3/R/R-3.2.1_install/lib64/R/include -DNDEBUG -DHAVE_PNG_H 
-I/usr/include/libpng12 -DHAVE_FREETYPE -Iext/ftgl -I/usr/include/freetype2 
-Iext -I/usr/local/include   -g -O2 -fvisibility=hidden -fpic  -g -O2  -c 
Background.cpp -o Background.o
g++ -I/files3/R/R-3.2.1_install/lib64/R/include -DNDEBUG -DHAVE_PNG_H 
-I/usr/include/libpng12 -DHAVE_FREETYPE -Iext/ftgl -I/usr/include/freetype2 
-Iext -I/usr/local/include   -g -O2 -fvisibility=hidden -fpic  -g -O2  -c 
ClipPlane.cpp -o ClipPlane.o
g++ -I/files3/R/R-3.2.1_install/lib64/R/include -DNDEBUG -DHAVE_PNG_H 
-I/usr/include/libpng12 -DHAVE_FREETYPE -Iext/ftgl -I/usr/include/freetype2 
-Iext -I/usr/local/include   -g -O2 -fvisibility=hidden -fpic  -g -O2  -c 
Color.cpp -o Color.o
g++ -I/files3/R/R-3.2.1_install/lib64/R/include -DNDEBUG -DHAVE_PNG_H 
-I/usr/include/libpng12 -DHAVE_FREETYPE -Iext/ftgl -I/usr/include/freetype2 
-Iext -I/usr/local/include   -g -O2 -fvisibility=hidden -fpic  -g -O2  -c 
Disposable.cpp -o Disposable.o
g++ -I/files3/R/R-3.2.1_install/lib64/R/include -DNDEBUG -DHAVE_PNG_H 
-I/usr/include/libpng12 -DHAVE_FREETYPE -Iext/ftgl -I/usr/include/freetype2 
-Iext -I/usr/local/include   -g -O2 -fvisibility=hidden -fpic  -g -O2  -c 
Light.cpp -o Light.o
g++ -I/files3/R/R-3.2.1_install/lib64/R/include -DNDEBUG -DHAVE_PNG_H 
-I/usr/include/libpng12 -DHAVE_FREETYPE -Iext/ftgl -I/usr/include/freetype2 
-Iext -I/usr/local/include   -g -O2 -fvisibility=hidden -fpic  -g -O2  -c 
LineSet.cpp -o LineSet.o
g++ 

Re: [R] Can't install rgl: installed package can't be loaded; 'memory not mapped'

2015-08-08 Thread Waichler, Scott R
  Hi, I can't install package rgl.  The last lines from the install process  
  talking
 about the error are:
 
 I'd guess you have an OpenGL problem.  Does glxgears run?

Yes, it does.  I wasn't aware of the program before you mentioned it, but a 
display opens with 3 gears and here is some output:
[root@hokulea R-3.2.1_install]# glxgears -info
GL_RENDERER   = Mesa GLX Indirect
GL_VERSION= 1.2 (1.5 Mesa 6.5.1)
GL_VENDOR = Mesa project: www.mesa3d.org
GL_EXTENSIONS = GL_ARB_depth_texture GL_ARB_imaging GL_ARB_multitexture 
GL_ARB_point_parameters GL_ARB_point_sprite GL_ARB_shadow 
GL_ARB_texture_border_clamp GL_ARB_texture_cube_map GL_ARB_texture_env_add 
GL_ARB_texture_env_combine GL_ARB_texture_env_crossbar GL_ARB_texture_env_dot3 
GL_ARB_texture_mirrored_repeat GL_ARB_texture_non_power_of_two 
GL_ARB_window_pos GL_EXT_abgr GL_EXT_bgra GL_EXT_blend_color 
GL_EXT_blend_func_separate GL_EXT_blend_minmax GL_EXT_blend_subtract 
GL_EXT_draw_range_elements GL_EXT_framebuffer_object GL_EXT_fog_coord 
GL_EXT_multi_draw_arrays GL_EXT_packed_pixels GL_EXT_rescale_normal 
GL_EXT_secondary_color GL_EXT_separate_specular_color GL_EXT_shadow_funcs 
GL_EXT_stencil_wrap GL_EXT_texture3D GL_EXT_texture_edge_clamp 
GL_EXT_texture_env_add GL_EXT_texture_env_combine GL_EXT_texture_env_dot3 
GL_EXT_texture_lod_bias GL_EXT_texture_object GL_EXT_vertex_array 
GL_ATI_texture_mirror_once GL_IBM_texture_mirrored_repeat GL_NV_blend_square 
GL_NV_texture_rectan!
 gle GL_NV_texgen_reflection GL_SGIS_generate_mipmap GL_SGIS_texture_lod 
GL_SGIX_depth_texture GL_SGIX_shadow
24839 frames in 6.0 seconds = 4153.389 FPS
7152 frames in 6.0 seconds = 1192.594 FPS
. . . 

Scott


  ** testing if installed package can be loaded
  sh: line 1: 11949 Segmentation fault  '/files3/R/R-
 3.2.1_install/lib64/R/bin/R' --no-save --slave 21 
 '/tmp/RtmpQCpp6N/file2b115f4f8e1d'
 
   *** caught segfault ***
  address (nil), cause 'memory not mapped'
  aborting ...
  ERROR: loading failed
 
  I realize this is probably not an R problem, but a Google search turns up
 nothing that helps, and I'm hoping someone here can help anyway.  Below
 are my sessionInfo() output and the contents of the first file generated with
 R CMD check rgl_0.95.1247.tar.gz.
 
  sessionInfo()
  R version 3.2.1 (2015-06-18)
  Platform: x86_64-unknown-linux-gnu (64-bit)
 
  locale:
   [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
   [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
   [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8
   [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
   [9] LC_ADDRESS=C   LC_TELEPHONE=C
  [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
 
  attached base packages:
  [1] stats graphics  grDevices utils datasets  methods   base
 
  loaded via a namespace (and not attached):
  [1] tools_3.2.1
 
 
  # R CMD check rgl_0.95.1247.tar.gz
  * installing *source* package 'rgl' ...
  ** package 'rgl' successfully unpacked and MD5 sums checked checking
  for gcc... gcc -std=gnu99 checking whether the C compiler works... yes
  checking for C compiler default output file name... a.out checking for
  suffix of executables...
  checking whether we are cross compiling... no checking for suffix of
  object files... o checking whether we are using the GNU C compiler...
  yes checking whether gcc -std=gnu99 accepts -g... yes checking for gcc
  -std=gnu99 option to accept ISO C89... none needed checking how to run
  the C preprocessor... gcc -std=gnu99 -E checking for gcc... (cached)
  gcc -std=gnu99 checking whether we are using the GNU C compiler...
  (cached) yes checking whether gcc -std=gnu99 accepts -g... (cached)
  yes checking for gcc -std=gnu99 option to accept ISO C89... (cached)
  none needed checking whether __attribute__((visibility())) is
  supported... yes checking whether gcc -std=gnu99 accepts
  -fvisibility... yes checking whether  accepts -fvisibility... no
  checking for libpng-config... yes
  configure: using libpng-config
  configure: using libpng dynamic linkage checking for X... libraries ,
  headers checking GL/gl.h usability... yes checking GL/gl.h presence...
  yes checking for GL/gl.h... yes checking GL/glu.h usability... yes
  checking GL/glu.h presence... yes checking for GL/glu.h... yes
  checking for glEnd in -lGL... yes checking for gluProject in -lGLU...
  yes checking for freetype-config... yes
  configure: using Freetype and FTGL
  configure: creating ./config.status
  config.status: creating src/Makevars
  ** libs
  g++ -I/files3/R/R-3.2.1_install/lib64/R/include -DNDEBUG -DHAVE_PNG_H -
 I/usr/include/libpng12 -DHAVE_FREETYPE -Iext/ftgl -
 I/usr/include/freetype2 -Iext -I/usr/local/include   -g -O2 
 -fvisibility=hidden
 -fpic  -g -O2  -c ABCLineSet.cpp -o ABCLineSet.o
  g++ -I/files3/R/R-3.2.1_install/lib64/R/include -DNDEBUG -DHAVE_PNG_H -
 I/usr/include/libpng12 -DHAVE_FREETYPE -Iext/ftgl -
 I/usr/include/freetype2 -Iext -I/usr/local/include   -g -O2 
 -fvisibility=hidden
 -fpic  -g -O2  -c 

[R] write.table with append=T after using cat on same file

2015-07-27 Thread Waichler, Scott R
Hi, 

For years I've been writing text to the beginning of files with cat(append=F) , 
then following that text with data written by write.table(append=T).  It is now 
giving me an error message.  I'm using R-3.1.2.  What gives?

df - data.frame(x = 1, y = 1:10, z = 10:1)
cat(file=junk.txt, sep=, # An introductory note.\n)
write.table(df, file=junk.txt, sep=,, append=T, quote=F, row.names=F, 
col.names=F)

Error in file(file, ifelse(append, a, w)) : invalid 'open' argument

Thanks,
Scott Waichler
Pacific Northwest National Laboratory
Richland, WA  USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Reading chunks of data from a file more efficiently

2014-08-09 Thread Waichler, Scott R
Hi,

I have some very large (~1.1 GB) output files from a groundwater model called 
STOMP that I want to read as efficiently as possible.  For each variable there 
are over 1 million values to read.  Variables are not organized in columns; 
instead they are written out in sections in the file, like this:

X-Direction Node Positions, m
 5.93145E+05  5.93155E+05  5.93165E+05  5.93175E+05
 5.93245E+05  5.93255E+05  5.93265E+05  5.93275E+05
. . . 
 5.94695E+05  5.94705E+05  5.94715E+05  5.94725E+05
 5.94795E+05  5.94805E+05  5.94815E+05  5.94825E+05

Y-Direction Node Positions, m
 1.14805E+05  1.14805E+05  1.14805E+05  1.14805E+05
 1.14805E+05  1.14805E+05  1.14805E+05  1.14805E+05
. . . 
 1.17195E+05  1.17195E+05  1.17195E+05  1.17195E+05
 1.17195E+05  1.17195E+05  1.17195E+05  1.17195E+05

Z-Direction Node Positions, m
 9.55000E+01  9.55000E+01  9.55000E+01  9.55000E+01
 9.55000E+01  9.55000E+01  9.55000E+01  9.55000E+01
. . .

I want to read and use only a subset of the variables.  I wrote the function 
below to find the line where each target variable begins and then scan the 
values, but it still seems rather slow, perhaps because I am opening and 
closing the file for each variable.  Can anyone suggest a faster way?

# Reads original STOMP plot file (plot.*) directly.  Should be useful when the 
plot files are
# very large with lots of variables, and you just want to retrieve a few of 
them.  
# Arguments:  1) plot filename, 2) number of nodes, 
# 3) character vector of names of target variables you want to return.
# Returns a list with the selected plot output.
READ.PLOT.OUTPUT6 - function(plt.file, num.nodes, var.names) {
  lines - readLines(plt.file)
  num.vars - length(var.names)
  tmp - list()
  for(i in 1:num.vars) {
ind - grep(var.names[i], lines, fixed=T, useBytes=T)
if(length(ind) != 1) stop(Not one line in the plot file with matching 
variable name.\n)
tmp[[i]] - scan(plt.file, skip=ind, nmax=num.nodes, quiet=T)
  }
  return(tmp)
}  # end READ.PLOT.OUTPUT6()

Regards,
Scott Waichler
Pacific Northwest National Laboratory
Richland, WA, USA
scott.waich...@pnnl.gov

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Using axis limits with plot3D

2014-08-06 Thread Waichler, Scott R
I would like to use the functions in the plot3D package but I am having trouble 
getting the axis limits to work correctly.  The slices plotted by the code 
below go beyond the bounds of the persp box and obscure the axis information.  
How can I show just the part of the domain within x.limits and y.limits?

library(plot3D)
x - z - seq(-4, 4, by=0.2)
y - seq(-6, 6, by=0.2)
M - mesh(x,y,z)
R - with(M, sqrt(x^2 + y^2 +z^2))
p - sin(2*R)/(R+1e-3)
x.limits - c(-2, 2)
y.limits - c(-2, 2)
slice3D(x,y,z, colvar=p, xs=0, ys=c(0, 4), zs=NULL, xlim=x.limits, 
ylim=y.limits, scale=F, ticktype=detailed)

Thanks,
Scott Waichler
Pacific Northwest National Laboratory
Richland, WA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Using apply with more than one matrix

2014-05-01 Thread Waichler, Scott R
 I would ask you to look at this loop-free approach and ask if this is not
 equally valid?
 
 ans - matrix(NA, ncol=2, nrow=2)
 ind.not.na - which(!is.na(a1))
 ans[] - condition1*a1[,,ind.not.na[1]]+ m2  # two matrices of equal
 dimensions, one logical.
  ans
  [,1] [,2]
 [1,]   NA 1.66
 [2,] 2.74   NA

Thanks, I am learning something.  I didn't know you could multiply a logical 
object by a numerical one.  But notice the answer is not the same as mine, 
because I am doing an operation on the vector of values a1[i,j,] first.  

I tried a modification on sapply below, but it doesn't work  because I haven't 
referenced the 3d array a1 properly.  So I guess I must try to get a 2d result 
from a1 first, then use that in matrix arithmetic.

Sapply or mapply may work, I haven't used these much and will try to learn 
better how to use them.  Your use of sapply looks good; but I'm trying to 
understand if and how I can bring in the operation on a1.  This doesn't work:

evaluate - function(idx) {
  ind.not.na - which(!is.na(a1[idx,])) ]))  # doesn't work; improper indexing 
for a1
  if(length(ind.not.na)  0) {
return(condition1*(a1[idx,ind.not.na[1]] + m2[idx]))  # doesn't work; 
improper indexing for a1
  }
}
vec - sapply(seq(length(m2)), evaluate)

Scott Waichler

 -Original Message-
 From: David Winsemius [mailto:dwinsem...@comcast.net]
 Sent: Wednesday, April 30, 2014 8:46 PM
 To: Waichler, Scott R
 Cc: Bert Gunter; r-help@r-project.org
 Subject: Re: [R] Using apply with more than one matrix
 
 
 On Apr 30, 2014, at 6:03 PM, Waichler, Scott R wrote:
 
  Here is a working example with no random parts.  Thanks for your
 patience and if I'm still off the mark with my presentation I'll drop the
 matter.
 
  v - c(NA, 1.5, NA, NA,
NA, 1.1, 0.5, NA,
NA, 1.3, 0.4, 0.9)
  a1 - array(v, dim=c(2,2,3))
  m1 - matrix(c(NA, 1.5, 2.1, NA), ncol=2, byrow=T)
  m2 - matrix(c(1.56, 1.64, 1.16, 2.92), ncol=2)
  condition1 - !is.na(m1) m1  m2
 
  ans - matrix(NA, ncol=2, nrow=2) # initialize for(i in 1:2) {  for(j
  in 1:2) {
 ind.not.na - which(!is.na(a1[i,j,]))
 if(condition1[i,j]  length(ind.not.na)  0) ans[i,j] -
  a1[i,j,ind.not.na[1]] + m2[i,j]  } } ans
  [,1] [,2]
  [1,]   NA 1.66
  [2,] 3.14   NA
 
 I would ask you to look at this loop-free approach and ask if this is not
 equally valid?
 
 ans - matrix(NA, ncol=2, nrow=2)
 ind.not.na - which(!is.na(a1))
 ans[] - condition1*a1[,,ind.not.na[1]]+ m2  # two matrices of equal
 dimensions, one logical.
  ans
  [,1] [,2]
 [1,]   NA 1.66
 [2,] 2.74   NA
 
  Let me try asking again in words.  If I have multiple matrices or slices
 of 3d arrays that are the same dimension, is there a way to pass them all
 to apply, and have apply take care of looping through i,j?
 
 I don't think `apply` is the correct function for this. Either `mapply` or
 basic matrix operation seem more likely to deliver correct results:
 
 
  I understand that apply has just one input object x.  I want to work on
 more than one array object at once using a custom function that has this
 characteristic:  in order to compute the answer at i,j I need a result
 from higher order array at the same i,j.
 
 If you want to iterate over matrix indices you can either use the vector
 version e.g. m2[3] or the matrix version, m2[2,1[.
 
 vec - sapply(seq(length(m2) , function(idx) m2[idx]*condition1[idx] )
 
 
 
  This is what I tried to demonstrate in my example above.
 
  Thanks,
  Scott
 
 David Winsemius
 Alameda, CA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Using apply with more than one matrix

2014-05-01 Thread Waichler, Scott R
  Sapply or mapply may work, I haven't used these much and will try to
 learn better how to use them.  Your use of sapply looks good; but I'm
 trying to understand if and how I can bring in the operation on a1.  This
 doesn't work:
 
  evaluate - function(idx) {
   ind.not.na - which(!is.na(a1[idx,])) ]))  # doesn't work; improper
  indexing for a1
   if(length(ind.not.na)  0) {
 return(condition1*(a1[idx,ind.not.na[1]] + m2[idx]))  # doesn't
  work; improper indexing for a1  } } vec - sapply(seq(length(m2)),
  evaluate)
 
 Are we to assume that the length of `which(!is.na(a1[idx,])) ]))` is
 guaranteed to equal the length of the two other matrices? If not then what
 sort of relationships should be assumed?

ind.not.na is just a vector that could be any length.  It is a selection on the 
vector a1[i,j,].  I want to get the first element of that selection.  The key 
relationship is that the dimensions of the matrices and the first two 
dimensions of the 3d arrays are the same.  That is, i and j have the same range 
for all of them.  

Scott

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Using apply with more than one matrix

2014-05-01 Thread Waichler, Scott R
Thank you, A.K.  I learned from both of your solutions.  I find the one that 
uses alply easier to follow and understand intuitively.  I guess I'll want to 
learn more about what plyr can do.  I've been using R for years but hadn't 
pushed vectorization far enough in my code.  Now my computing will be more 
efficient.  

Thanks also to David and the others who responded to my question.  It all 
helped.  --Scott Waichler

 -Original Message-
 From: arun [mailto:smartpink...@yahoo.com]
 Sent: Thursday, May 01, 2014 6:24 AM
 To: R. Help
 Cc: Waichler, Scott R
 Subject: Re: [R] Using apply with more than one matrix
 
 Hi,
 Sorry, a typo in the previous function:
 -
 if (condition1[i]  !is.na(indx3)) {
     arr[x1][indx3] + m2[i]  ## should be mat2[i]
     } else NA
 
 ---
 
 Also, you can try:
 library(plyr)
 evaluateNew - function(arr, mat1, mat2){ if (!all(dim(mat1) ==
 dim(mat2))) {
     stop(both matrices should have equal dimensions)
     }
  indx1 - unlist(alply(arr, c(1,2), function(x) {x[!is.na(x)][1]}))
 condition1 - !is.na(mat1)  mat1  mat2 ifelse(condition1, indx1+mat2,
 NA) } evaluateNew(a1, m1, m2)
 
 #    [,1] [,2]
 #[1,]   NA 1.66
 #[2,] 3.14   NA
 A.K.
 
 
 
 
 On Thursday, May 1, 2014 5:49 AM, arun smartpink...@yahoo.com wrote:
 
 
 Hi,
 
 You may try:
 evaluate - function(arr, mat1, mat2) {
     if (!all(dim(mat1) == dim(mat2))) {
     stop(both matrices should have equal dimensions)
     }
     indx1 - as.matrix(do.call(expand.grid, lapply(dim(arr), sequence)))
     indx2 - paste0(indx1[, 1], indx1[, 2])
     condition1 - !is.na(mat1)  mat1  mat2
     ans - sapply(seq_along(unique(indx2)), function(i) {
     x1 - indx1[indx2 %in% unique(indx2)[i], ]
     indx3 - which(!is.na(arr[x1]))[1]
     if (condition1[i]  !is.na(indx3)) {
     arr[x1][indx3] + m2[i]
     } else NA
     })
     dim(ans) - dim(mat1)
     ans
 }
 evaluate(a1,m1,m2)
 # [,1] [,2]
 #[1,]   NA 1.66
 #[2,] 3.14   NA
 
 A.K.
 
 
 
 On Thursday, May 1, 2014 2:53 AM, Waichler, Scott R
 scott.waich...@pnnl.gov wrote:
  I would ask you to look at this loop-free approach and ask if this is
  not equally valid?
 
  ans - matrix(NA, ncol=2, nrow=2)
  ind.not.na - which(!is.na(a1))
  ans[] - condition1*a1[,,ind.not.na[1]]+ m2  # two matrices of equal
 dimensions, one logical.
   ans
       [,1] [,2]
  [1,]   NA 1.66
  [2,] 2.74   NA
 
 Thanks, I am learning something.  I didn't know you could multiply a
 logical object by a numerical one.  But notice the answer is not the same
 as mine, because I am doing an operation on the vector of values a1[i,j,]
 first.
 
 I tried a modification on sapply below, but it doesn't work  because I
 haven't referenced the 3d array a1 properly.  So I guess I must try to get
 a 2d result from a1 first, then use that in matrix arithmetic.
 
 Sapply or mapply may work, I haven't used these much and will try to learn
 better how to use them.  Your use of sapply looks good; but I'm trying to
 understand if and how I can bring in the operation on a1.  This doesn't
 work:
 
 evaluate - function(idx) {
   ind.not.na - which(!is.na(a1[idx,])) ]))  # doesn't work; improper
 indexing for a1
   if(length(ind.not.na)  0) {
     return(condition1*(a1[idx,ind.not.na[1]] + m2[idx]))  # doesn't work;
 improper indexing for a1
   }
 }
 vec - sapply(seq(length(m2)), evaluate)
 
 Scott Waichler
 
 
  -Original Message-
  From: David Winsemius [mailto:dwinsem...@comcast.net]
  Sent: Wednesday, April 30, 2014 8:46 PM
  To: Waichler, Scott R
  Cc: Bert Gunter; r-help@r-project.org
  Subject: Re: [R] Using apply with more than one matrix
 
 
  On Apr 30, 2014, at 6:03 PM, Waichler, Scott R wrote:
 
   Here is a working example with no random parts.  Thanks for your
  patience and if I'm still off the mark with my presentation I'll drop
  the matter.
  
   v - c(NA, 1.5, NA, NA,
         NA, 1.1, 0.5, NA,
         NA, 1.3, 0.4, 0.9)
   a1 - array(v, dim=c(2,2,3))
   m1 - matrix(c(NA, 1.5, 2.1, NA), ncol=2, byrow=T)
   m2 - matrix(c(1.56, 1.64, 1.16, 2.92), ncol=2)
   condition1 - !is.na(m1) m1  m2
  
   ans - matrix(NA, ncol=2, nrow=2) # initialize for(i in 1:2) {
  for(j  in 1:2) {
      ind.not.na - which(!is.na(a1[i,j,]))
      if(condition1[i,j]  length(ind.not.na)  0) ans[i,j] -
  a1[i,j,ind.not.na[1]] + m2[i,j]  } } ans
       [,1] [,2]
   [1,]   NA 1.66
   [2,] 3.14   NA
 
  I would ask you to look at this loop-free approach and ask if this is
  not equally valid?
 
  ans - matrix(NA, ncol=2, nrow=2)
  ind.not.na - which(!is.na(a1))
  ans[] - condition1*a1[,,ind.not.na[1]]+ m2  # two matrices of equal
 dimensions, one logical.
   ans
       [,1] [,2]
  [1,]   NA 1.66
  [2,] 2.74   NA
  
   Let me try asking again in words.  If I have multiple matrices or
   slices
  of 3d arrays that are the same dimension, is there a way to pass them
  all to apply, and have apply take care of looping through i,j?
 
  I don't

[R] Using apply with more than one matrix

2014-04-30 Thread Waichler, Scott R
Hi,

I want to apply a custom function to all the elements of one matrix.  The 
function uses the value in the same i,j in a second matrix.  How can I use 
apply() or similar function to avoid nested loops in i and j?

Thanks,
Scott Waichler
Pacific Northwest National Laboratory
Richland, WA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Using apply with more than one matrix

2014-04-30 Thread Waichler, Scott R
Ok, here is a toy example.  I want to use a custom function that depends on 
more than one matrix/array as input, and I can't figure out how to do that with 
apply. 

v - c(NA, 1.5, NA, NA,
   NA, 1.1, 0.5, NA,
   NA, 1.3, 0.4, 0.9)
a1 - array(v, dim=c(2,2,3))
m1 - matrix(c(NA, 1.5, 2.1, NA), ncol=2, byrow=T)
m2 - matrix(runif(n=4, min=1, max=3), ncol=2)
condition1 - ifelse(!is.na(m1)  m1  m2, T, F)

ans - matrix(NA, ncol=2, nrow=2) # initialize
for(i in 1:2) {
  for(j in 1:2) {
ind.not.na - which(!is.na(a1[i,j,]))
if(condition1[i,j]  length(ind.not.na)  0) {
  ans[i,j] - a1[i,j,ind.not.na[1]] + m2[i,j]
}
  }
}

Scott Waichler



 -Original Message-
 From: Bert Gunter [mailto:gunter.ber...@gene.com]
 Sent: Wednesday, April 30, 2014 12:18 PM
 To: Waichler, Scott R
 Cc: r-help@r-project.org
 Subject: Re: [R] Using apply with more than one matrix
 
 Scott:
 
 Your problem specification is rather vague: What do you mean by use?
 
 In general, matrices are merely vectors with a dim attribute, so if you
 can do what you want with them as vectors, then that will work for them as
 matrices. For example:
 
  m1- matrix(1:6, nr=3)
  m2 - matrix(11:16, nr=2)
  m2*m2
  [,1] [,2] [,3]
 [1,]  121  169  225
 [2,]  144  196  256
 
 If this does not meet your needs, you will have to follow the posting
 guide and provide both code and a minimal reproducible example.
 
 Cheers,
 Bert
 
 
 Bert Gunter
 Genentech Nonclinical Biostatistics
 (650) 467-7374
 
 Data is not information. Information is not knowledge. And knowledge is
 certainly not wisdom.
 H. Gilbert Welch
 
 
 
 
 On Wed, Apr 30, 2014 at 10:54 AM, Waichler, Scott R
 scott.waich...@pnnl.gov wrote:
  Hi,
 
  I want to apply a custom function to all the elements of one matrix.
 The function uses the value in the same i,j in a second matrix.  How can I
 use apply() or similar function to avoid nested loops in i and j?
 
  Thanks,
  Scott Waichler
  Pacific Northwest National Laboratory
  Richland, WA, USA
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Using apply with more than one matrix

2014-04-30 Thread Waichler, Scott R
Here is a working example with no random parts.  Thanks for your patience and 
if I'm still off the mark with my presentation I'll drop the matter.  

v - c(NA, 1.5, NA, NA,
   NA, 1.1, 0.5, NA,
   NA, 1.3, 0.4, 0.9)
a1 - array(v, dim=c(2,2,3))
m1 - matrix(c(NA, 1.5, 2.1, NA), ncol=2, byrow=T)
m2 - matrix(c(1.56, 1.64, 1.16, 2.92), ncol=2)
condition1 - !is.na(m1) m1  m2

ans - matrix(NA, ncol=2, nrow=2) # initialize
for(i in 1:2) {
  for(j in 1:2) {
ind.not.na - which(!is.na(a1[i,j,]))
if(condition1[i,j]  length(ind.not.na)  0) ans[i,j] - 
a1[i,j,ind.not.na[1]] + m2[i,j]
  }
}
ans
 [,1] [,2]
[1,]   NA 1.66
[2,] 3.14   NA

Let me try asking again in words.  If I have multiple matrices or slices of 3d 
arrays that are the same dimension, is there a way to pass them all to apply, 
and have apply take care of looping through i,j?  I understand that apply has 
just one input object x.  I want to work on more than one array object at once 
using a custom function that has this characteristic:  in order to compute the 
answer at i,j I need a result from higher order array at the same i,j.  This is 
what I tried to demonstrate in my example above.

Thanks,
Scott

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] problem with pip2d() from ptinpoly

2014-04-19 Thread Waichler, Scott R
Thank you for catching that, Boris.  I'm surprised, given that there is no 
mention of sense of direction in the package documentation.

Scott Waichler

 -Original Message-
 From: Boris Steipe [mailto:boris.ste...@utoronto.ca]
 Sent: Friday, April 18, 2014 3:49 PM
 To: Waichler, Scott R; r-help@r-project.org
 Subject: Re: [R] problem with pip2d() from ptinpoly
 
 Apparently it matters whether your polygon is defined clockwise or
 counterclockwise.
 
 A point outside your triangle is recognized ...
  q2 - matrix(c(594893.0,115435.0), ncol=2, byrow=T) pip2d(Vertices =
  verts, Queries = q2)
 [1] 1
 
 ... and defining the triangle in counterclockwise sense gives the expected
 behaviour.
  v2 - matrix(c(594891,115309,594891,117201,59,117201), ncol=2,
  byrow=T) pip2d(Vertices = v2, Queries = query)
 [1] 1
 
 Cheers,
 B.

 On 2014-04-18, at 6:00 PM, Waichler, Scott R wrote:
 
  Hi,
 
  pip2d() doesn't seem to work correctly for me.  I have a plot of a
 triangle that a query point fits inside, but the point is defined as
 outside the polygon by pip2d.
 
  library(ptinpoly)
  verts - matrix(c(594891,115309,59,117201,594891,117201), ncol=2,
  byrow=T) query - matrix(c(594885.0,115435.0), ncol=2, byrow=T)
  pip2d(Vertices = verts, Queries = query)  # result = -1 # contrary to
  -1 output of pip2d, plot shows point lies within triangle
  plot(c(594400, 595000), c(115000, 117500), type=n) polygon(verts,
  border=red) points(x=query[,1], y=query[,2], col=blue)
 
  Scott Waichler
  Pacific Northwest National Laboratory
  Richland, WA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] problem with pip2d() from ptinpoly

2014-04-18 Thread Waichler, Scott R
Hi,

pip2d() doesn't seem to work correctly for me.  I have a plot of a triangle 
that a query point fits inside, but the point is defined as outside the polygon 
by pip2d.  

library(ptinpoly)
verts - matrix(c(594891,115309,59,117201,594891,117201), ncol=2, byrow=T)
query - matrix(c(594885.0,115435.0), ncol=2, byrow=T)
pip2d(Vertices = verts, Queries = query)  # result = -1
# contrary to -1 output of pip2d, plot shows point lies within triangle
plot(c(594400, 595000), c(115000, 117500), type=n)
polygon(verts, border=red)
points(x=query[,1], y=query[,2], col=blue)

Scott Waichler
Pacific Northwest National Laboratory
Richland, WA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] vector field from a 3D scalar field

2013-03-21 Thread Waichler, Scott R
I have a 3D field of a scalar variable (x, y, z, value).  Is there a way to 
generate a vector field from this data--gradient at defined points?  I found 
the rasterVis package for 2D data, but as yet nothing for 3D data.

Thanks,
Scott Waichler
Pacific Northwest National Laboratory
Richland, WA
scott.waich...@pnnl.gov

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] how to get xmlToList() to retry if http fails

2013-03-06 Thread Waichler, Scott R
Hi,

I am using xmlToList() in a loop with a call to a webservice, per the code 
below.  

  # Loop thru target locs
  for(i in 1:num.target.locs) {
url - paste(sep=/, http://www.earthtools.org/timezone;, lat[i], lon[i])
tmp - xmlToList(url)
df$time.offset[i] - tmp$offset
system(sleep 1)  # wait 1 second per requirements of above web service
  }  # end loop thru target locations

Failure struck midway through my loop, with the message below.

failed to load HTTP resource
Error: 1: failed to load HTTP resource

I presume that the webservice failed to respond in this instance.  How can I 
trap the error and have it retry after waiting a second or two, instead of 
exiting?

Thanks.  --Scott Waichler
Pacific Northwest National Laboratory
Richland, WA, USA
scott.waich...@pnnl.gov

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Can't get R to recognize Java for rJava installation

2012-04-13 Thread Waichler, Scott R
Milan,

Merci.  I did find the javah file and put it in /usr/bin, where R can now find 
it.  
However, I still get a similar error message when trying to install rJava, i.e. 

configure: error: One or more Java configuration variables are not set.

The only field that doesn't have a value now are the cpp flags:

cpp flags   : ''

Could this be the problem now?  How can I set those, and what value should I 
give?

Scott Waichler

 So I guess you need to find out what package provides this file on your
 distribution (which you did not mention). First check the file is
 currently not present.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Can't read a binary file

2012-04-13 Thread Waichler, Scott R
Hi, I've read up on readBin() and chapter 6 in the R Data Import/Export manual, 
but I still can't read a binary file.  Here is how the creator of the file 
described the code that would be needed in Fortran:

Every record has a return in fortran.  The length of each record is nx*ny*4.  
To read you would use the following:

nlayx = nx*ny*4
do iz=1,nz,4
 read(binary file) var(1:nlayx)
enddo
nrest=mod(nx*ny*nz,nlayx)
read(binary file) var(1:nrest)

The first value in the file should be 0.05, and all of the data values are 
real.  Here is what I get (with similar answers using double):

 v-readBin(plotb.251, numeric(), size=4, n=1)
 v
[1] 1.614296e-39

 v-readBin(plotb.251, numeric(), size=4, n=1, endian=swap)
 v
[1] 1.359775e-38

Platform is Intel Linux.  How can I read the file described above?

Thanks,
Scott Waichler, PhD
Hydrology Group, Energy  Environment Directorate
Pacific Northwest National Laboratory
scott.waich...@pnnl.gov

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Can't get R to recognize Java for rJava installation

2012-04-12 Thread Waichler, Scott R
Hi, I am unable to install the package rJava.  I tried doing what the output 
suggests, but it doesn't help.  How can I get R to find/recognize my Java 
installation?  I am running R-2.15.0.

waichler@snow sudo R CMD javareconf
Java interpreter : /usr/bin/java
Java version : 1.6.0_22
Java home path   : /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/jre
Java compiler: /usr/bin/javac
Java headers gen.:
Java archive tool: /usr/bin/jar
Java library path: 
$(JAVA_HOME)/lib/i386/client:$(JAVA_HOME)/lib/i386:$(JAVA_HOME)/../lib/i386:/usr/java/packages/lib/i386:/lib:/usr/lib
JNI linker flags : -L$(JAVA_HOME)/lib/i386/client -L$(JAVA_HOME)/lib/i386 
-L$(JAVA_HOME)/../lib/i386 -L/usr/java/packages/lib/i386 -L/lib -L/usr/lib -ljvm
JNI cpp flags:

Updating Java configuration in /usr/lib/R
Done.

 install.packages(c(rJava), dependencies = T, repos = 
 http://cran.fhcrc.org;)
. . . 
checking whether siglongjmp is declared... yes
checking Java support in R... present:
interpreter : '/usr/bin/java'
archiver: '/usr/bin/jar'
compiler: '/usr/bin/javac'
header prep.: ''
cpp flags   : ''
java libs   : '-L/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/jre/lib/i386/client 
-L/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/jre/lib/i386 
-L/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/jre/../lib/i386 
-L/usr/java/packages/lib/i386 -L/lib -L/usr/lib -ljvm'
configure: error: One or more Java configuration variables are not set.
Make sure R is configured with full Java support (including JDK). Run
R CMD javareconf
as root to add Java support to R.

If you don't have root privileges, run
R CMD javareconf -e
to set all Java-related variables and then install rJava.

ERROR: configuration failed for package ÆrJavaÇ
* removing Æ/usr/lib/R/library/rJavaÇ

Thanks,
Scott Waichler
Senior Research Scientist
Hydrology Group, Energy  Environment Directorate
Pacific Northwest National Laboratory

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Alternative to interp.surface() offered

2011-10-24 Thread Waichler, Scott R
This is a correction to a post from 3/10/09.  I just wanted to get this in the 
archive.  It is the same thread as 

http://www.mail-archive.com/r-help@r-project.org/msg48762.html

Thanks to Matt Oliver for bringing this to my attention.  

The correct code for my.interp.surface() follows.

# A function for  bilinear interpolation on a 2-d grid, based on
# interp.surface() from the fields package and code by Steve Koehler.
# The points of the grid do not have to be uniformly spaced.
# findInterval() is used to locate on the grid.
my.interp.surface - function (obj, loc) {
  # obj is a list with known x, y, z.
  # loc a matrix of new x, y locations at which you want z values.
  x - sort(unique(obj$x))
  y - sort(unique(obj$y))
  x.new - loc[,1]
  y.new - loc[,2]
  z - obj$z
  ind.x - findInterval(x.new, x, all.inside=T)
  ind.y - findInterval(y.new, y, all.inside=T)

  ex - (x.new - x[ind.x]) / (x[ind.x + 1] - x[ind.x])
  ey - (y.new - y[ind.y]) / (y[ind.y + 1] - y[ind.y])

  ex[ex  0 | ex  1] - NA
  ey[ey  0 | ey  1] - NA

  return(
  z[cbind(ind.x, ind.y)] * (1 - ex) * (1 - ey) +  # upper left
  z[cbind(ind.x, ind.y + 1)] * (1 - ex) * ey   +  # lower left
  z[cbind(ind.x + 1, ind.y + 1)] * ex   * ey   +  # lower right
  z[cbind(ind.x + 1, ind.y)] * ex   * (1 - ey)# upper right
)
}


Scott Waichler
Pacific Northwest National Laboratory
scott.waich...@pnnl.gov

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] How to find regions enclosed by edges within a TIF image

2011-09-16 Thread Waichler, Scott R
I am processing grayscale TIF images that represent X-rays of a sand- and 
gravel-filled tube.  Each image represents a plane through the porous medium, 
and I need to classify each pixel in the image as void or solid.  For the most 
part, voids are dark and solids are bright, but there are many gray regions.  
In particular, there are obvious pebbles (larger sized solids) that have darker 
spots within them, which get erroneous classification as voids.  Can anyone 
suggest packages/functions that I could use to identify pebbles by their edges 
(roundish areas outlined by voids), so I could then classify those regions as 
solid?  So far I am using just the adimpro package, to read the TIF files.

Thanks,
Scott Waichler
Pacific Northwest National Laboratory
scott.waich...@pnnl.gov

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] 3-D response surface using wireframe()

2010-04-08 Thread Waichler, Scott R
Regarding the screen argument in wireframe(), here is what I understand about 
how it works after much trial-and-error:

After each rotation, new axes are in effect defined for the next rotation as at 
the start:  x is to the right of the 2D view, y is towards the top, and z is 
positive out of the page towards you.  Understanding this reset of coordinate 
system after each rotation is key to understanding how the sequence of 
rotations will be done.  Rotations follow the right-hand rule:  positive angles 
follow curved fingers of right hand, with thumb pointing in positive direction 
of associated axis.

I labeled a wooden block with axes and turned it in my hand to help me make the 
initial guess at the sequence of rotations I would want for a given view.  

Scott Waichler
Pacific Northwest National Laboratory
P.O. Box 999, Richland, WA  99352
scott.waich...@pnl.gov
509-372-4423, 509-341-4051 (cell)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Eliminate border in wireframe plot

2010-03-15 Thread Waichler, Scott R
How can I eliminate the border drawn by default around a wireframe plot?  I've 
tried using border=NA and box=FALSE to no avail.  

Scott Waichler
Pacific Northwest National Laboratory
scott.waich...@pnl.gov

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Cut-aways with contour3d

2010-03-15 Thread Waichler, Scott R
Luke,

Thanks for your previous advice on using misc3d; I've been able to get a good 
start with it.  Most of my colleagues use Tecplot for graphing and are 
wondering if I can make cut-aways using R.  An example is attached.  The idea 
is show a 3D isosurface of one property together with a 2D cross section of 
another property.  Is that possible with contour3d?  I also need other plot 
components and so am using wireframe and the grid engine.  If it's possible, 
can you give me an idea of how to proceed?

Thanks,
Scott Waichler

Pacific Northwest National Laboratory
Richland, WA, USA
scott.waich...@pnl.gov
509-372-4423, 509-341-4051 (cell)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Screen settings for point of view in lattice and misc3d

2010-03-03 Thread Waichler, Scott R
I'm making some 3D plots with contour3d from misc3d and wireframe from lattice. 
 I want to view them from below; i.e. the negative z-axis.  I can't figure out 
how to do so.  I would like my point of view looking up from below, with the z, 
y, and x axes positive going away.  Can anyone tell me the correct settings for 
screen to achieve this?  Here is what I've found so far:

 screen=list(z=-40, x=-60, y=0), # looking down and away in negative x direction
 screen=list(z=40, x=60, y=0),  # domain turned upside down, looking up and 
away in neg. x direction
 screen=list(z=-40, x=60, y=0),  # domain turned upside down, looking up and 
away in pos. x direction
 screen=list(z=40, x=-60, y=0), # looking down and away in positive x 
direction


Scott Waichler
Pacific Northwest National Laboratory
P.O. Box 999, Richland, WA  99352
scott.waich...@pnl.gov
509-372-4423, 509-341-4051 (cell)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Using contour3d: axes, plotting to file, with lattice

2010-02-12 Thread Waichler, Scott R
 Some of the examples in the JSS paper http://www.jstatsoft.org/v28/i01
 might be useful for integrating contour3d results with lattice.

Thank you, Luke, for pointing me to your paper with examples beyond what is in 
R help.  The example of using contour3d and wireframe in lattice in Section 4.4 
will be very helpful to me.  

Scott Waichler
Pacific Northwest National Laboratory
P.O. Box 999, Richland, WA  99352
scott.waich...@pnl.gov
509-372-4423, 509-341-4051 (cell)



 
 luke
 
 On Thu, 11 Feb 2010, Waichler, Scott R wrote:
 
  I am looking for examples of how to plot with contour3d() to a PNG or
 PDF file, add axes and other elements to the isosurface plot, and use
 contour3d in conjunction with lattice.  Regarding lattice, I'm not
 necessarily looking for conditioning on the data shown in the isosurface
 plots, just a way to show multiple plots in one figure and label them.  I
 am new to the packages misc3d and rgl.
 
  Thanks,
  Scott Waichler

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Using contour3d: axes, plotting to file, with lattice

2010-02-11 Thread Waichler, Scott R
I am looking for examples of how to plot with contour3d() to a PNG or PDF file, 
add axes and other elements to the isosurface plot, and use contour3d in 
conjunction with lattice.  Regarding lattice, I'm not necessarily looking for 
conditioning on the data shown in the isosurface plots, just a way to show 
multiple plots in one figure and label them.  I am new to the packages misc3d 
and rgl.  

Thanks,
Scott Waichler
Pacific Northwest National Laboratory
scott.waich...@pnl.gov

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Output from as.windrose() in oce package baffles me

2009-09-04 Thread Waichler, Scott R
Dan,

 May I ask you to report this as an issue on the oce webpage,
 so that others can see the discussion?  (The R help is 
 perhaps not the right place to report bugs ... and, yes, this 
 is a bug.) 
   http://code.google.com/p/r-oce/issues/list

Yes, I will.

 A possible solution is to edit the windrose.R file and 
 replace the first function with what I am putting below.  But 
 I am actually not sure on the if (theta... line, and need 
 to think about that some more.  Also, please note that 
 official releases of OCE take some time (typically a week) so 
 that's why I always suggest a workaround, first.  As I'm sure 
 you're aware, you could just source a file containing the 
 code below, after doing the library(oce), and that will 
 work until a new release comes out.  I have been holding off 
 on a release for quite a while, since I am working on code to 
 handle acoustic-doppler data from about a half-dozen 
 instruments, and I try to avoid letting anyone get caught out 
 by using code that is still in development.
 
 as.windrose - function(x, y, dtheta = 15) {
  dt - dtheta * pi / 180
  dt2 - dt / 2
  R - sqrt(x^2 + y^2)
  angle - atan2(y, x)
  L - max(R, na.rm=TRUE)
  nt - 2 * pi / dt
  theta - count - mean - vector(numeric, nt)
  fivenum - matrix(0, nt, 5)
  for (i in 1:nt) {
  theta[i] - i * dt
  if (theta[i] = pi)
  inside - (angle  (theta[i] + dt2))  
 ((theta[i] - dt2) = angle)
  else {
  inside - ((2*pi+angle)  (theta[i] + dt2))  ((theta[i]
 - dt2) = (2*pi+angle))
  }
  count[i] - sum(inside)
  mean[i] - mean(R[inside], na.rm=TRUE)
  fivenum[i,] - fivenum(R[inside], na.rm=TRUE)
  }
  data - list(n=length(x), x.mean=mean(x, na.rm=TRUE), 
 y.mean=mean (y, na.rm=TRUE), theta=theta*180/pi, count=count, 
 mean=mean,
 fivenum=fivenum)
  metadata - list(dtheta=dtheta)
  log - processing.log.item(paste(deparse(match.call()), sep=,
 collapse=))
  res - list(data=data, metadata=metadata, processing.log=log)
  class(res) - c(windrose, oce)
  res
 }

I decided to not use the windrose object created by as.windrose().
Instead, I wrote my own function for plotting wind speed and wind
direction data, using some of the features from plot.windrose().  The
data I work with is usually provided in mph or m/s and azimuth degrees,
so I found it more convenient to provide those directly as arguments to
the function.  Three utility functions come first, followed by the main
one of interest, PLOT.WINDROSE2().

degrees - function(radians) {
  return(radians * 180 / pi)
}

radians - function(degrees) {
  return(degrees * pi / 180)
}

# Define a function that converts compass headings (bearings, azimuths)
into geometric angles for trigonometry.
# Examples:  For a heading = 0 degrees, vector points due north, and
angle = 90 deg.
# For a heading = 90 degrees, vector points east, and angle = 0 deg.
convert.heading.angle - function(heading) {
  num.heading - length(heading)
  angles - rep(NA, num.heading)
  for(i in 1:num.heading) {
angles[i] -
  ifelse((heading[i] =0  heading[i] = 90), 90 - heading[i], 
 ifelse((heading[i] =90  heading[i] = 180), 360 -
(heading[i] - 90),
ifelse((heading[i] =180  heading[i] = 270), 180
+ (270 - heading[i]), 90 + (360 - heading[i]))
   )
)
  }
  return(angles)
}  # end of convert.heading.angle()


# A function to plot windroses, with similar output capabilities as that
of plot.windrose() function   
# in the oce package.  This function has not been extensively tested.  
# Theta should be in ascending order, starting at some azimuth  0
degrees.
# The oce package was written by Dan Kelley.
# Arguments:
# 1) vector of windspeeds
# 2) vector of wind directions (azimuths, degrees; 0=calm, 45=NE, 90=E,
180=S, 270=W, 360=N)
#AZIMUTH DEGREES ARE COMPASS BEARINGS
# 3) vector of windrose sector centers (azimuths, degrees)
# 4) type of windrose plot:  count, mean, median, or fivenum
# 5) color vector for use as in plot.windrose()
# 6) plot title
PLOT.WINDROSE2 - function(ws, az, theta, type=c(count, mean,
median, fivenum), col, title, ...) {
  type - match.arg(type)
  nt - length(theta)  # number of sectors
  az.ar - radians(az) # convert azimuth degrees to radians
  t - radians(theta)  # convert sector centers to radians
  dt - t[2] - t[1]  # angle range for each sector (radians)
  if(dt  0) stop(Center angles for theta must be in increasing
order.\n)
  if((sum(diff(theta)) + theta[2]-theta[1]) != 360) stop(Sectors do not
add up to 360 degrees.\n)
  dt2 - dt / 2  # radians
  sector.boundaries - c(t - dt2, t[nt] + dt2)  # sector boundaries in
azimuth radians
  # bin the azimuths into the sectors
  ind.sector - ifelse(az.ar  sector.boundaries[1], nt,
findInterval(az.ar, sector.boundaries))

  # Bin the azimuth data into the defined sectors
  calm - ifelse(az == 0, T, F)  # 

[R] Output from as.windrose() in oce package baffles me

2009-09-03 Thread Waichler, Scott R
I'm having trouble understanding the output from as.windrose().  For one
thing, data on a boundary between sectors seem to be left out of the
counts.  I assume that explains the missing point in the output below
(angle 45).  Shouldn't one side of each sector interval be open, to
include values such as my 45 in the example?  Also, why does the angle
180 in my input apparently not result in a count of 1 for the output for
180?  The $data$theta value of 180 refers to a sector centered at 180
whose angle is 90, correct?

library(oce)

# azimuths - c(22.5, 45, 90, 180, 270)  # 0 and 360=north, 90=east,
180=south, 270=west
angles - c(67.5, 45, 0, 270, 180)  # geometric equivalents of azimuths
radians - angles * pi /180
x - round(cos(radians), 6)
y - round(sin(radians), 6)
w - as.windrose(x, y, dtheta = 90) # make a windrose object, oce
package

# part of windrose object w:
$data$theta
[1]  90 180 270 360

$data$count
[1] 1 0 1 1

Thanks,
Scott Waichler
Pacific Northwest National Laboratory
scott.waich...@pnl.gov

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] RPMs for R on the Redhat EPEL site

2009-08-02 Thread Waichler, Scott R
Martyn,

 The maintainer of the RHEL RPMs no longer has an i386 machine 
 running EL4, and cross-building on an x86_64 machine did not 
 work, so I did not distribute them.
 
 As noted in a previous thread, there is a project to port the 
 Fedora R RPMs to Enterprise Linux:
 
 On Thursday 23 April 2009 15:08:26 Marc Schwartz wrote:
  More info here:
 
 http://fedoraproject.org/wiki/EPEL
 
  and the specific link for R for RHEL 4/x84_64 is:
 
 
 http://download.fedora.redhat.com/pub/epel/4/x86_64/repoview/R.html


I went to the EPEL site, but it appears that the links to the R-2.9.1
RPMs are just text files, ~17 km in size, e.g. the link below.  Do you
know where the actual RPMs are?  I don't know what a metapackage
means.

http://download.fedora.redhat.com/pub/epel/4/i386/R-2.9.1-1.el4.i386.rpm

Thanks,
Scott

Scott Waichler, Senior Research Scientist
Pacific Northwest National Laboratory
MSIN K9-36
P.O. Box 999
Richland, WA   99352USA
509-372-4423 (voice)
509-372-6089 (fax)
scott.waich...@pnl.gov
http://hydrology.pnl.gov

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Binaries no longer compiled for RH EL4, i386?

2009-04-30 Thread Waichler, Scott R
I see that R 2.9.0 *.rpms have been compiled for RH EL5, i386 and
x86_64, and also for EL4 x86_64, but not for EL4 i386.  Is this an
oversight or will that version no longer be compiled?

Scott Waichler
Pacific Northwest National Laboratory
scott.waich...@pnl.gov

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Alternative to interp.surface() offered

2009-03-10 Thread Waichler, Scott R
I wanted a simple function for bilinear interpolation on a 2-D grid, and
interp.surface() in the fields package didn't quite suit my needs.  In
particular, it requires uniform spacing between grid points.  It also
didn't have the visual reference frame I was looking for.  Here is an
alternative function, followed by an example.

# A function for  bilinear interpolation on a 2-d grid, based on the
# interp.surface() from the fields package and code by Steve Koehler.
# The points of the grid do not have to be uniformly spaced.  Looking at
the 2-d
# grid in plan view, the origin is at upper left, so y (row) index
increases
# downward.  findInterval() is used to locate the new coordinates on the
grid.
#
# Scott Waichler, scott.waich...@pnl.gov, 03/10/09.  

my.interp.surface - function (obj, loc) {
  # obj is a surface object like the list for contour or image.
  # loc is a matrix of (x, y) locations 
  x - obj$x
  y - obj$y
  x.new - loc[,1]
  y.new - loc[,2]
  z - obj$z

  ind.x - findInterval(x.new, x, all.inside=T)
  ind.y - findInterval(y.new, y, all.inside=T)

  ex - (x.new - x[ind.x]) / (x[ind.x + 1] - x[ind.x])
  ey - (y.new - y[ind.y]) / (y[ind.y + 1] - y[ind.y])

  # set weights for out-of-bounds locations to NA
  ex[ex  0 | ex  1] - NA
  ey[ey  0 | ey  1] - NA

  return(
  z[cbind(ind.y, ind.x)] * (1 - ex) * (1 - ey) +  # upper
left
  z[cbind(ind.y + 1, ind.x)] * (1 - ex) * ey   +  # lower
left
  z[cbind(ind.y + 1, ind.x + 1)] * ex   * ey   +  # lower
right
  z[cbind(ind.y, ind.x + 1)] * ex   * (1 - ey)# upper
right
)
}

## # An example.
## # z matrix, y index increasing downwards
## #   4 5 6 7 8
## #   3 4 5 6 7
## #   2 3 4 5 6
## #   1 2 3 4 5
## z.vec - c(4,5,6,7,8,3,4,5,6,7,2,3,4,5,6,1,2,3,4,5) # read in the
data for the matrix
## x.mat - 1:5# x coordinates of the z values
## y.mat - seq(100, 400, by=100)  # y coordinates of the z values
## obj - list(x = x.mat, y = y.mat, z = matrix(z.vec, ncol=5, byrow=T))
# grid you want to interpolate on
## x.out - round(runif(6, min = min(x.mat), max = max(x.mat)), 2)  # x
for points you want interpolate to
## y.out - round(runif(6, min = min(y.mat), max = max(y.mat)), 2)  # y
for points you want interpolate to
## loc - cbind(x.out, y.out)
## z.out - my.interp.surface(obj, loc)
## cat(file=, x.out = , loc[,1], \n, y.out = , loc[,2], \n,
z.out = , round(z.out, 2), \n)

Regards,
Scott Waichler
Pacific Northwest National Laboratory
Richland, WA   99352USA
scott.waich...@pnl.gov

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] rimage doesn't install on Mac OS X 10.4

2008-11-12 Thread Waichler, Scott R
Hi,

I'm trying to install rimage on a Mac OS X 10.4 machine.  I followed the
advice in previous R-help threads and got over the hurdles of having the
header files in the right places, among other things.  But I can't
figure out what to do with this error.

ice.pnl.gov:/home/waichler949system_profiler -detailLevel mini
SPSoftwareDataType
Software: System Software Overview:
  System Version: Mac OS X 10.4.11 (8S165)
  Kernel Version: Darwin 8.10.0
ice.pnl.gov:/home/waichler942echo $C_INCLUDE_PATH
/usr/local/include
ice.pnl.gov:/home/waichler946echo $MACOSX_DEPLOYMENT_TARGET
10.4

ice.pnl.gov:/home/waichler947sudo R CMD INSTALL
--configure-vars='LDFLAGS=-L/sw/lib CPPFLAGS=-I/sw/include'
/Users/ladmin/rimage_0.5-7.tar.gz
. . . 
gcc -arch ppc -std=gnu99
-I/Library/Frameworks/R.framework/Resources/include
-I/Library/Frameworks/R.framework/Resources/include/ppc -g -O2
-I/sw/include-I/usr/local/include-fPIC  -g -O2 -c sobel.c -o sobel.o
g++ -arch ppc -dynamiclib -Wl,-headerpad_max_install_names
-mmacosx-version-min=10.4 -undefined dynamic_lookup -single_module
-multiply_defined suppress -L/usr/local/lib -o rimage.so equalize.o
fftw_access_func.o freqfilters.o interface.o jpegio.o laplacian.o
matrix.o smooth.o sobel.o -L/sw/lib -ljpeg -lfftw
-F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework
-Wl,CoreFoundation
ld: /Library/Frameworks/R.framework/../R.framework/R load command 14
unknown cmd field
/usr/bin/libtool: internal link edit command failed
make: *** [rimage.so] Error 1
chmod:
/Library/Frameworks/R.framework/Versions/2.8/Resources/library/rimage/li
bs/ppc/*: No such file or directory
ERROR: compilation failed for package 'rimage'

(I have also tried to install the package from the Mac GUI for R, but it
quits at not being able to find the jpeglib.h file, which I solved in
the command line session excerpted above using setenv C_INCLUDE_PATH
/usr/local/include.)

Scott Waichler
Pacific Northwest National Laboratory
[EMAIL PROTECTED]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Using a background photo in lattice--title and axes missing

2008-11-06 Thread Waichler, Scott R
 I am trying to use a background photo in a lattice plot.  I 
 am using the rimage and TeachingDemos packages to plot the 
 photo and translate from the photo coordinates in pixels to 
 geographic coordinates, which is what I want to use for 
 plotting contours, lines, etc.  The (unrunable) code below 
 does give me a plot showing the photo, color contours, 
 contour lines, and colorkey, but not the plot title or axes.  
 How can I get the title and axes to appear?

Nevermind, I figured out that all I needed was to add the statement
par(new=T) before plot(photo).

Regards,
Scott Waichler

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Using a background photo in lattice--title and axes missing

2008-11-05 Thread Waichler, Scott R
I am trying to use a background photo in a lattice plot.  I am using the
rimage and TeachingDemos packages to plot the photo and translate from
the photo coordinates in pixels to geographic coordinates, which is what
I want to use for plotting contours, lines, etc.  The (unrunable) code
below does give me a plot showing the photo, color contours, contour
lines, and colorkey, but not the plot title or axes.  How can I get the
title and axes to appear?

  # Define a panel function that fills the true contoured regions with
color.
  # This requires the gridBase package.  panel.contourplot() gives a
stair-step, rectangular
  # pattern caused by the underlying grid.  This custom function from
Deepayan Sarkar
  # fills the contour color regions right up to the contour lines
themselves.
  # This version uses pre-defined colors.
  panel.filledContour2 - function(x, y, z, subscripts, at, col =
my.colors, ...) {
stopifnot(require(gridBase))
stopifnot(require(rimage))  # use for plotting a background photo
stopifnot(require(TeachingDemos)) # use for changing from photo
coordinates (pixels) to geographic coordinates
z - matrix(z[subscripts], nrow = length(unique(x[subscripts])),
ncol = length(unique(y[subscripts])))
if (!is.double(z)) storage.mode(z) - double
opar - par(no.readonly = TRUE)
on.exit(par(opar))
if (panel.number()  1) par(new = TRUE)
par(fig = gridFIG(), omi = c(0, 0, 0, 0), mai = c(0, 0, 0, 0))
cpl - current.panel.limits() # set the plot window boundaries to
the current panel limits
plot.window(xlim = cpl$xlim, ylim = cpl$ylim, log = , xaxs = i,
yaxs = i)

# Plot the background photo
plot(photo)

# Change from photo to geographic coordinate systems.
# Reference two points in the image coordinate system to the new
coordinate system.
# x1, y1 are in the photo coordinates; x2, y2 are the map/plotting
coordinates you want to work in.
updateusr(x1 = photo.resize.factor * x1r, y1 = photo.resize.factor *
y1r, x2 = x2r, y2 = y2r)

# Plot the color contours
.Internal(filledcontour(as.double(do.breaks(cpl$xlim, nrow(z) - 1)),
as.double(do.breaks(cpl$ylim, ncol(z) - 1)),
z, levels = as.double(at), col = col))

# Add contour lines
contour(as.double(do.breaks(cpl$xlim, nrow(z) - 1)),
as.double(do.breaks(cpl$ylim, ncol(z) - 1)),
z, levels = as.double(at), col = black,
drawlabels=T, add=T, labcex=0.8)
  }  # end of panel.filledContour2()

  plotfile - plotfile2b
  png(file = plotfile, width=11, height=8.5, units=in, res=75,
pointsize=12)  # landscape letter
  
  my.cuts - seq(0, 90, by=10)
  my.colors - rev(BluetoOrange.10[1:9]) # orange to blue (warm to cold
with increasing time)
  #my.colors - rgb(col2rgb(my.colors)/255, alpha=0.2)  # make
translucent; only works for pdf, quartz devices
  
  x.limits - c(593600, 593950)
  x.ticks - pretty(x.limits, n=5)
  y.limits - c(113300, 113530)
  y.ticks - pretty(y.limits, n=5)
  
  p$time[ind.neg] - 0
  ind - ind.all.times.injected
  di - interp(x=p$x[ind], y=p$y[ind], z=p$time[ind], duplicate=mean,
linear=T, 
   xo=seq(x.limits.photo[1], x.limits.photo[2], length =
300), yo=seq(y.limits.photo[1], y.limits.photo[2], length = 300))
  ia - which(!is.na(di$z))
  grid - expand.grid(x=di$x, y=di$y)
  
  plot.new()
  
  # contour plot doesn't print a key by default
  print(contourplot(di$z ~ x * y, grid,
# Plot head as filled color contours
panel = panel.filledContour2, subscripts = 1:length(grid$x),

at = my.cuts,
col.regions = my.colors,
colorkey=T,
contour = TRUE, 
aspect=iso, 
as.table=T,
scales = list(x = list(relation=same, alternating = T,
   at =x.ticks.photo, labels = x.ticks.photo,
   limits=x.limits.photo
  ), 
  y = list(relation=same, alternating = T,
   at = y.ticks.photo, labels = y.ticks.photo,
   rot=0,
   limits=y.limits.photo
  )
  ),
xlab=list(label=X (m), cex=1.1),
ylab=list(label=Y (m), cex=1.1),
layout=c(1,1), # ncols, nrows
main=list(label=Particle Travel Times, cex=1.2),
strip = F,   # set to FALSE if you don't want strip drawn in plot (a
subtitle)
plot.args = list(newpage = FALSE)
  )) # end print(xyplot())
  dev.off()


Thanks,
Scott Waichler
Pacific Northwest National Laboratory
[EMAIL PROTECTED]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Using an image background with graphics

2008-10-21 Thread Waichler, Scott R
Dr. Ripley,

Thank you, yes, it's the anti-aliasing thing again.  I'm using Redhat
EL4, R-2.8.0, and pdf().  I had the problem with images displayed in
xpdf, even with xpdf -aa no.  I do not get the problem in Adobe Reader
7.0 for Linux.  I'll try harder to remember this point.
 
Scott Waichler
Pacific Northwest National Laboratory
[EMAIL PROTECTED]

 Most likely this is a bug in your pdf viewer: try turning off 
 anti-aliasing there (or use a better viewer, if that is not 
 an option).
 It is a symptom of anti-aliasing of the rectangles used to 
 plot image pixels.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Using an image background with graphics

2008-10-20 Thread Waichler, Scott R
Greg,

 The rimage package has functions for reading in and plotting 
 jpeg files that you could use for displaying the photograph.  
 If you then can find 2 points in the image (not on the same 
 horizontal or vertical line) for which you know the 
 coordinates in the coordinate system that you want to plot 
 in, then you can use the updateusr function from the 
 TeachingDemos package to set the user coordinates, then use 
 points/lines or other functions that can add to the current 
 plot (e.g. contour with add=TRUE) to overlay the information 
 of interest to the plot.

I tried this, and your approach works great except for one thing.  I
would like to plot to a pdf device, and when I do so my grayscale image
takes on a gridded appearance, with thick horizontal and vertical lines
of lighter gray.  These don't appear of course if I use jpeg() instead
of pdf().  How can I get rid of those?

Thanks,
Scott Waichler
[EMAIL PROTECTED]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Using an image background with graphics

2008-10-13 Thread Waichler, Scott R

I would like to use a map or aerial photo as a background to plotting
solid lines and text, and semi-transparent color contours, in base and
lattice graphics.  Plot coordinates need to be consistent with the
georeferenced background.  For example, a color contour plot would have
an gray-toned aerial photograph as a background for overprinted
semi-transparent color contours of some spatially dependent variable.
Can anyone point me in the right direction on how to do this?

Thanks,
Scott Waichler
Pacific Northwest National Laboratory
[EMAIL PROTECTED]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] error installing lattice package

2008-10-08 Thread Waichler, Scott R
I just updated my Redhat EL systems to R-2.7.2, and tried to update my
packages as well.  Lattice is one that failed.  What do I need to do?

R version 2.7.2 (2008-08-25)

 install.packages(lattice, repos = http://cran.fhcrc.org/;)
Warning in install.packages(lattice, repos = http://cran.fhcrc.org/;)
:
  argument 'lib' is missing: using '/usr/lib/R/library'
trying URL 'http://cran.fhcrc.org/src/contrib/lattice_0.17-15.tar.gz'
Content type 'application/x-gzip' length 281977 bytes (275 Kb)
opened URL
==
downloaded 275 Kb

* Installing *source* package 'lattice' ...
** libs
gcc -I/usr/include/R  -I/usr/local/include-fpic  -O2 -g -std=gnu99
-c init.c -o init.o
init.c:2:15: R.h: No such file or directory
init.c:3:24: Rinternals.h: No such file or directory
init.c:4:28: R_ext/Rdynload.h: No such file or directory
In file included from init.c:6:
threeDplot.h:5:22: Rdefines.h: No such file or directory
In file included from init.c:6:
threeDplot.h:9: error: syntax error before wireframePanelCalculations
threeDplot.h:9: error: syntax error before xArg
threeDplot.h:15: warning: type defaults to `int' in declaration of
`wireframePanelCalculations'
threeDplot.h:15: warning: data definition has no type or storage class
init.c:8: error: syntax error before CallEntries
init.c:8: warning: type defaults to `int' in declaration of
`CallEntries'
init.c:9: warning: braces around scalar initializer
init.c:9: warning: (near initialization for `CallEntries[0]')
init.c:9: warning: initialization makes integer from pointer without a
cast
init.c:9: error: `DL_FUNC' undeclared here (not in a function)
init.c:9: warning: excess elements in scalar initializer
init.c:9: warning: (near initialization for `CallEntries[0]')
init.c:9: warning: excess elements in scalar initializer
init.c:9: warning: (near initialization for `CallEntries[0]')
init.c:10: warning: braces around scalar initializer
init.c:10: warning: (near initialization for `CallEntries[1]')
init.c:10: error: `NULL' undeclared here (not in a function)
init.c:10: error: initializer element is not constant
init.c:10: error: (near initialization for `CallEntries[1]')
init.c:10: warning: excess elements in scalar initializer
init.c:10: warning: (near initialization for `CallEntries[1]')
init.c:10: warning: excess elements in scalar initializer
init.c:10: warning: (near initialization for `CallEntries[1]')
init.c:10: error: initializer element is not constant
init.c:10: error: (near initialization for `CallEntries[1]')
init.c:11: warning: data definition has no type or storage class
init.c:13: error: syntax error before '*' token
init.c: In function `R_init_lattice':
init.c:15: warning: implicit declaration of function
`R_registerRoutines'
init.c:15: error: `dll' undeclared (first use in this function)
init.c:15: error: (Each undeclared identifier is reported only once
init.c:15: error: for each function it appears in.)
init.c:16: warning: implicit declaration of function
`R_useDynamicSymbols'
init.c:16: error: `FALSE' undeclared (first use in this function)
make: *** [init.o] Error 1
ERROR: compilation failed for package 'lattice'
** Removing '/usr/lib/R/library/lattice'
** Restoring previous '/usr/lib/R/library/lattice'

Thanks,
Scott Waichler
Pacific Northwest National Laboratory
[EMAIL PROTECTED]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] error installing lattice package

2008-10-08 Thread Waichler, Scott R
  I just updated my Redhat EL systems to R-2.7.2, and tried 
 to update my 
  packages as well.  Lattice is one that failed.  What do I 
 need to do?
 
 Install the R-devel RPM?  (Assuming you installed R from an RPM.)

Yes, I installed R from an RPM.  Installing the R-devel RPM worked on
one machine without any trouble, but it required a number of other
prerequisite RPMs on other machines.  I never had this trouble before in
updating R with an RPM.  Also, even on the machine where R-devel worked,
updating of four packages still failed, for lack of header files, etc.
I guess I'll just hope that R-2.8 doesn't have these problems for me.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Creating smooth color regions with panel.contourplot()

2008-09-18 Thread Waichler, Scott R
Thank you very much, Deepayan.  There is just one more feature I'd like
to get, the ability to add the contour lines.  My revision to your code
below prints too many lines.  What needs to be changed?  

--Thanks,
Scott Waichler
[EMAIL PROTECTED]

library(gridBase)
library(lattice)
data(volcano)

panel.filledcontour - function(x, y, z, subscripts, at, col.regions =
cm.colors,
col = col.regions(length(at) - 1), ...)
{
  stopifnot(require(gridBase))
  z - matrix(z[subscripts],
  nrow = length(unique(x[subscripts])),
  ncol = length(unique(y[subscripts])))
  if (!is.double(z)) storage.mode(z) - double
  opar - par(no.readonly = TRUE)
  on.exit(par(opar))
  if (panel.number()  1) par(new = TRUE)
  par(fig = gridFIG(), omi = c(0, 0, 0, 0), mai = c(0, 0, 0, 0))
  cpl - current.panel.limits()
  plot.window(xlim = cpl$xlim, ylim = cpl$ylim,
  log = , xaxs = i, yaxs = i)
  # paint the color contour regions
  .Internal(filledcontour(as.double(do.breaks(cpl$xlim, nrow(z) - 1)),
  as.double(do.breaks(cpl$ylim, ncol(z) - 1)),
  z, as.double(at), col = col))

  # add the contour lines--this prints too many of them.  I really want
just
  # the lines dividing the color regions.
  contour(as.double(do.breaks(cpl$xlim, nrow(z) - 1)),
as.double(do.breaks(cpl$ylim, ncol(z) - 1)),
z, as.double(at), add=T,
  col = gray, # color of the lines
  drawlabels=F  # add labels or not
 )
}

pdf(volcano.pdf)
plot.new()

print(levelplot(volcano, panel = panel.filledcontour,
  col.regions = terrain.colors,
  cuts = 10,
  plot.args = list(newpage = FALSE)))
dev.off()

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Creating smooth color regions with panel.contourplot()

2008-09-18 Thread Waichler, Scott R
  Thank you very much, Deepayan.  There is just one more feature I'd 
  like to get, the ability to add the contour lines.  My revision to 
  your code below prints too many lines.  What needs to be changed?

 You need to name arguments here. as.double(at) is being 
 matched to 'nlevels', but you want 'levels'.
 
 Another option is to use panel.levelplot() for the contours. 
 E.g., (also with more accurate 'x' and 'y'):
 
 panel.filledcontour -
function(x, y, z, subscripts,
 at,
 col.regions = cm.colors,
 col = col.regions(length(at) - 1),
 ...)
 {
stopifnot(require(gridBase))
z - matrix(z[subscripts],
nrow = length(unique(x[subscripts])),
ncol = length(unique(y[subscripts])))
if (!is.double(z)) storage.mode(z) - double
opar - par(no.readonly = TRUE)
on.exit(par(opar))
if (panel.number()  1)
par(new = TRUE)
par(fig = gridFIG(), omi = c(0, 0, 0, 0), mai = c(0, 0, 0, 0))
cpl - current.panel.limits()
plot.window(xlim = cpl$xlim, ylim = cpl$ylim,
log = , xaxs = i, yaxs = i)
.Internal(filledcontour(as.double(sort(unique(x[subscripts]))),
as.double(sort(unique(y[subscripts]))),
z, as.double(at), col = col))
panel.contourplot(x, y, z, subscripts = subscripts, at = at,
region = FALSE, contour = TRUE, labels = FALSE) }

The contour lines do not exactly line up with some of the color breaks.
I see this in the volcano example as well as the figure I'm trying to
make.  

--Scott Waichler

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Creating smooth color regions with panel.contourplot()

2008-09-18 Thread Waichler, Scott R
 Does the contour() solution work? If not, there's not really 
 much that can be done.

Yes, I figured out how to add the naming of arguments.  This works
great:

library(gridBase)
library(lattice)
data(volcano)

panel.filledcontour - function(x, y, z, subscripts, at, col.regions =
cm.colors,
col = col.regions(length(at) - 1), ...)
{
  stopifnot(require(gridBase))
  z - matrix(z[subscripts],
  nrow = length(unique(x[subscripts])),
  ncol = length(unique(y[subscripts])))
  if (!is.double(z)) storage.mode(z) - double
  opar - par(no.readonly = TRUE)
  on.exit(par(opar))
  if (panel.number()  1) par(new = TRUE)
  par(fig = gridFIG(), omi = c(0, 0, 0, 0), mai = c(0, 0, 0, 0))
  cpl - current.panel.limits()
  plot.window(xlim = cpl$xlim, ylim = cpl$ylim,
  log = , xaxs = i, yaxs = i)
  # paint the color contour regions
  .Internal(filledcontour(as.double(do.breaks(cpl$xlim, nrow(z) - 1)),
  as.double(do.breaks(cpl$ylim, ncol(z) - 1)),
  z, levels = as.double(at), col = col))
  # add contour lines
  contour(as.double(do.breaks(cpl$xlim, nrow(z) - 1)),
  as.double(do.breaks(cpl$ylim, ncol(z) - 1)),
  z, levels = as.double(at), add=T,
  col = gray, # color of the lines
  drawlabels=F  # add labels or not
 )
}

pdf(volcano.pdf)
plot.new()

print(levelplot(volcano, panel = panel.filledcontour,
  col.regions = terrain.colors,
  cuts = 10,
  plot.args = list(newpage = FALSE)))
dev.off()

--Scott Waichler

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Still no R-2.7.2 rpms for Redhat Enterprise Linux

2008-09-18 Thread Waichler, Scott R
There's already an announcement about R 2.8.0, and yet there are still
no R-2.7.2 binaries (rpms) for Redhat Enterprise Linux 4 and 5.  Can the
usual responsible party get on it?  Can the system be improved to get
more timely builds out on CRAN?

Thanks,
Scott Waichler
Pacific Northwest National Laboratory

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Parallel computing with rgenoud and snow: external file I/O possible?

2008-05-14 Thread Waichler, Scott R
I am trying to use rgenoud and snow with an external model and file I/O.
Unlike the typical application of rgenoud and snow, I need to run an
external executable and do pre- and post-processing of input and output
files for each parameter set generated by genoud().  I'm hoping that
someone can suggest improvements to my approach and a work-around for
file I/O problems I've encountered when trying to do this in parallel
processing under snow.  I'm using the SOCK cluster type. 

An external executable (the model) and file input and output for that
model are used.  For this example, the model is simply R's sin()
function, packaged in such a way that it is called by a shell script.
The model reads an input file and writes an output file.  My example
involves two nodes on different machines.  Each model run launched by
genoud uses a working directory named after the node to hold the
temporary input and output files.  The function called by genoud,
drive.calib(), saves the parameter and objective function values in a
file also named after the node, and after genoud finishes, the results
from all the runs are combined in one file for convenience.  I realize
that the communications in this simple example take much longer than the
model execution.  In my real application of concern the model runtimes
will be much longer than the communication time.

To simplify the scripts further, I tried to pass the variable
working.dir as an additional argument in genoud(), but it didn't work.
I seem to have to specify all the working.dir pathnames before the
genoud() call as well as the specific one for the particular model
execution inside the function drive.calib().  Also, a relative pathname
for the working directory does not work; I found I had to use absolute
pathnames.  

If I wanted to use more than one chip on the same machine, I believe I
would have to use random numbers to create unique directory names and
prevent conflict between model executions.  However, in my
trial-and-error development, I found that genoud and/or the cluster are
very touchy about file handling, and it was necessary to create the
working directories before genoud() was called, thus effectively
preventing me from using multiple chips on the same machine.  If you
have any insights as to why or can suggest a work-around, it would be
appreciated.  

The pasted-in files below are as follows:  test_cluster.r, the main R
script; call_R.csh, a shell script that calls the model; sin.r, an R
script that is the model.  Together call_R.csh and sin.r make up the
external model.

Thanks for any help,
Scott Waichler
Pacific Northwest National Laboratory 
Richland, WA  USA
509-372-4423 (voice)
509-372-6089 (fax)
[EMAIL PROTECTED]

 test_cluster.r
---
#  test_cluster.r
#
#  R script to test the parallelization capability.
#  This uses rgenoud and external processes outside of R, and file I/O.
#  These are the key characteristics of work with stand-alone models.

library(snow)  # Simple Network of Workstations
#library(rlecuyer) # for random number generator
library(rgenoud)   # calibrator of choice

# Set the working directory--must be an absolute pathname.  Also put
this statement inside
# drive.calib(), the function that is called by genoud().  I cannot get
genoud() to pass this
# as an argument without breaking.
working.dir - /projects/dhsvm/uvm/test/rhelp/

results.file - test_results.txt  # file to save results in

# Set up the cluster
this.host - system(hostname, intern=T)
node - c(this.host, escalante)  # add additional nodes here
setDefaultClusterOptions(master=this.host, type=SOCK, homogeneous=T,
outfile=/tmp/cluster1)
cl - makeCluster(node)
#clusterSetupRNG(cl)  # init random number generator to ensure each node
has a different seed

# Define the function that will be called by genoud()
drive.calib - function(xx) {  # parameter value that is being adjusted
  
  working.dir - /projects/dhsvm/uvm/test/rhelp/ # HARDWIRED WORKING
DIRECTORY
  
  this.host - as.character(system(hostname, intern=T))
  #this.rn - sample(1:1e6, 1)  # get a random number
  #this.dir - paste(sep=, working.dir, this.host, _, this.rn)  #
hostname and random number
  this.dir -  paste(sep=, working.dir, this.host)   # hostname only
  infile -  paste(sep=/, this.dir, tmp.in)   # input to external
model
  outfile - paste(sep=/, this.dir, tmp.out) # output from external
model
  
  # file that holds input parameter values and results for all model
runs on this node
  results.file - paste(sep=, this.dir, .out) 
  
  cat(file=infile, append=F, xx) # write the input file for the model

  # run the external model
  system(paste(sep=, working.dir, call_R.csh , this.dir), intern =
F, ignore.stderr = TRUE)

  # read the result from the external model run
  score - scan(file=outfile, quiet=T)
  
  # save the parameter value and result for this model run
  cat(file=results.file, append=T, xx, score, \n)

  return(score) # 

[R] Using aggregate() and apply() on circular data

2008-01-08 Thread Waichler, Scott R
I would like to use aggregate.ts() and apply() on circular data, but I
can't figure out how to get the circular data components to pass
through:

library(circular)
x - circular(c(20, 30, 355, 5, 345, 25), units = degrees)

% I want to get the mean angle for each successive pair; answer should
be c(25, 0, 5):
aggregate.ts(x, ndeltat=2, FUN=mean.circular)
Error in as.circular(x) :
  (converted from warning) an object is coerced to the class 'circular'
using default value for the following components:
  type: 'angles'
  units: 'radians'
  template: 'none'
  modulo: 'asis'
  zero: 0
  rotation: 'counter'
conversion.circularxradians0counter

% Using mean() disregards the circular nature of the data:
aggregate.ts(x, ndeltat=2, FUN=mean)
Time Series:
Start = 1
End = 5
Frequency = 0.5
[1]  25 180 185

% I have similar problems with apply():
y - matrix(x, ncol=2, byrow=T)
% Both of the following expressions yield the same error message as
above.
apply(y, 1, FUN=mean.circular)
apply(circular(y, units = degrees), 1, FUN=mean.circular)

I've tried passing various additional arguments to aggregate.ts() and
apply() to specify the circular components, without success.

Scott Waichler
Pacific Northwest National Laboratory
[EMAIL PROTECTED]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Range of circular data

2008-01-07 Thread Waichler, Scott R
I want to get the minimum arc (in degrees) needed to include a set of
compass directions.  I would like to use the range.circular() function
of the package circular, because that package understands a compass-type
of angle convention, but it gives results I don't understand.  Howver, I
can get the correct answer in the example below, 90 degrees, using the
CircStats package.  How can I make the circular package work for me?

 R.version.string
[1] R version 2.6.1 (2007-11-26)

 library(circular)
 y - circular(c(45, 135), units = degrees, template = geographics)
 range.circular(y)
Circular Data:
Type = angles
Units = degrees
Template = geographics
Modulo = asis
Zero = 1.570796
Rotation = clock
[1] 0

Just in case range.circular() expects radians, I tried this:

 range.circular(rad(y))
Circular Data:
Type = angles
Units = degrees
Template = geographics
Modulo = asis
Zero = 1.570796
Rotation = clock
[1] 88.4292

I can get the correct answer using CircStats instead:

 library(CircStats)
 y - rad(c(45, 135))
 180*circ.range(y)/pi
  range
190

Thanks,
Scott Waichler
Pacific Northwest National Laboratory
scott.waichler _at_ pnl.gov

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.