[R] how to pass 'raw' values with cfunction()?

2012-03-17 Thread Dan Kelley
I am having trouble handing raw data to a C function, using cfunction, as demonstrated in the function and output pasted below. Can anyone suggest what I'm doing incorrectly? Thanks. Dan Kelley [Dalhousie University]. 1. TEST FILE library(inline) code - 'Rprintf(inside f(), b is 0X%x\\n

Re: [R] how to pass 'raw' values with cfunction()?

2012-03-17 Thread Dan Kelley
), 0x0f); return(R_NilValue);' f - cfunction(sig=signature(b=raw), body=code, convention=.Call) b - as.raw(0x0f) for (i in 1:5) f(b) On 2012-03-17, at 2:49 PM, Dirk Eddelbuettel wrote: On 17 March 2012 at 14:34, Dan Kelley wrote: | I am having trouble handing

Re: [R] how to pass 'raw' values with cfunction()?

2012-03-17 Thread Dan Kelley
=code, verbose=TRUE, convention=.Call) b - as.raw(0x0f) for (i in 1:5) f(b) On 2012-03-17, at 3:02 PM, Dan Kelley wrote: Thanks. .Call is better. But how do I get the actual value of the byte (0F)? (Updated code below. I does not compile if I use as_RAW(*b

[R] recommendations on use of - operator

2010-03-18 Thread Dan Kelley
think a convention might help, what would that convention be? Dan Kelley, PhD Professor and Graduate Coordinator Dept. Oceanography, Dalhousie University, Halifax NS B3H 4J1 kelley@gmail.com (1-minute path on US server) or dan.kel...@dal.ca (2-hour path on Cdn server) Phone 902 494 1694; Fax

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

2009-09-04 Thread Dan Kelley
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

Re: [R] problem loading ncdf library on MAC

2009-08-13 Thread Dan Kelley
Update: I could not get RNetCDF working because I couldn't install udunits version 1 properly, and udunits2 is not the right version. However, returning to the original post, I *did* get ncdf working. Just install it from source. Then, you can do as e.g. below pre library(ncdf) jpeg(SSS.jpg,

Re: [R] problem loading ncdf library on MAC

2009-08-12 Thread Dan Kelley
I think ncdf is broken now, and so is Rnetcdf. I can't build from source, either. If I find a solution, I'll post it here. FYI, I have an intel-based Mac running the latest OS and with R 2.9.1 -- View this message in context:

Re: [R] problem loading ncdf library on MAC

2009-08-12 Thread Dan Kelley
Right. I have udunits2 installed, but that's not enough. It seems to want udunits, instead, even though the latter is deprecated. I downloaded the older package from http://www.unidata.ucar.edu/downloads/udunits/index.jsp but it does not compile, e.g. ../port/cfortran/cfortran.h:133:3:

Re: [R] S_alloc or Calloc for return value

2009-07-21 Thread Dan Kelley
I'm afraid I am missing something. In my R function (call it foo, say) I am doing something like foo - function() { ... .C(bar, ..., res=integer(n), ...)$res } but I don't know the n to use; that is determined inside my C function bar. Is there a way around this?

Re: [R] S_alloc or Calloc for return value

2009-07-21 Thread Dan Kelley
Self-posting the solution, to help those who come across this thread with a similar interest -- My solution, arrived at with the generous help of those who have replied to my question, was to use .Call, as exemplified below. My task was to find indices in a raw buffer (input) that match a

[R] S_alloc or Calloc for return value

2009-07-20 Thread Dan Kelley
I am trying to write a C function to create a vector of integers that can be used by the R calling function. I do not know the size of the vector in the R calling function. (Well, actually, I have an upper limit on the size, but that is so large that R cannot allocate it. What I'm doing in the

[R] inconsistent results for axis.POSIXct

2009-05-11 Thread Dan Kelley
Some time ago, I posted a note about what I considered to be a bug in axis.POSIXt() for R 2.8.x, relating to whether timezones in the data are obeyed on the axes. A link to that note, and to a quick and helpful response, is at the following URL

[R] Rd: how to put a prime in a code fragment?

2009-04-18 Thread Dan Kelley
I have written a function for my 'oce' package that creates a data.frame containing a variable name with a prime in it. (I use prime to indicate coordinate rotation, a reasonably standard convention that motivates the odd variable name.) How can I name that in an Rd file? I tried \code{u'} but

[R] how to index statements provided as function args?

2009-04-15 Thread Dan Kelley
Is there a way to specify a *vector* of statements, as an argument to a function. What I'm trying to do is to provide the ability to add elements to a series of panels drawn by a function. (As documented, split.screen does not provide this capability.) My idea is to mimic the 'plot.axes'

Re: [R] how to index statements provided as function args?

2009-04-15 Thread Dan Kelley
That works perfectly. Thanks very much!! Duncan Murdoch-2 wrote: On 15/04/2009 6:31 AM, Dan Kelley wrote: Is there a way to specify a *vector* of statements, as an argument to a function. There are several ways. expression() converts its arguments into a vector of expressions, e.g

[R] re form data for aov()?

2009-03-29 Thread Dan Kelley
I'm trying to follow along in a text by Velleman and others, with the 'handwashing' example of anova. I used read.table() to read the data, and now I have an object d (put below the dots here), with an entry Method that has possible values Water, Soap, etc. What I can't figure out is how to

[R] re form data for aov()?

2009-03-29 Thread Dan Kelley
I have data in a file named hands.dat, which is given at the end of this question. (It's from a stats textbook example on anova). I'd like to do an aov on this, which I guess would be d - read.table(~/hands.dat, header=TRUE) aov(Bacterial.Counts ~ Water + Soap + Antibacterial.Soap +

Re: [R] re form data for aov()?

2009-03-29 Thread Dan Kelley
As a followup, I show below what I get if I break out the variables by making a new data frame with new (boolean) columns that indicate the treatment. (The experiment was germ count on hands, after cleansing with 4 different methods.) What I'm hoping is to find a way to do this in a less

[R] how to use axes=FALSE to get multple plots?

2009-02-10 Thread Dan Kelley
I am trying to plot two things on one graph, with a y-axis at the left for one variable, and a y-axis at the right, for the other variable. I thought I could do as follows par(mar=rep(4.5, 4)) plot(0:10, 10:20) par(new=TRUE) plot(0:10, 100:110, axes=FALSE) axis(4) but this writes both y-axis

Re: [R] how to use axes=FALSE to get multple plots?

2009-02-10 Thread Dan Kelley
Duncan Murdoch-2 wrote: ...Are you really sure you want a graph with two different scales on it? Thanks, Duncan. I'll use mtext. It is common for people in my research area to put several axes on plots. The top two panels from library(oce) data(ctd) plot(ctd) shows this. Actually,

Re: [R] tcltk, tcltk2, Rcmdr, Mac OS X

2009-02-10 Thread Dan Kelley
I just installed Rcmd on my OSX-10.5 32-bit powerpc box, with R 2.8.1, and it seems to work (see below). Beyond that, I can't help, since I've not used this package. Good luck! library(Rcmdr) Loading required package: tcltk Loading Tcl/Tk interface ... done Loading required package: car

Re: [R] how to manipulate ... within a function

2008-12-20 Thread Dan Kelley
Thanks very much, Duncan. In case it's of interest to others who encounter this thread later, I am pasting below the code I wrote. It is for the 'oce' package for oceanographic data, which explains the reversal of the y axis, forming a so-called 'profile', in which the top of the graph

[R] how to manipulate ... within a function

2008-12-18 Thread Dan Kelley
Is there a way a function ('parent', say) can manipulate the ... argument, and then pass the manipulated value into another function ('child', say) that it calls? What I'm trying to do is to use some plotting defaults within 'parent' that are not part of parent's argument list, but to let the

[R] can a function alter the ... argument and passed the result to another function?

2008-12-18 Thread Dan Kelley
Is there a way a function ('parent', say) can manipulate the ... argument, and then pass the manipulated value into another function ('child', say) that it calls? What I'm trying to do is to use some plotting defaults within 'parent' that are not part of parent's argument list, but to let

Re: [R] bug in difftime with as.POSIXct

2008-01-27 Thread Dan Kelley
Oh, I'm sorry to be posting a reply to my own stupid question, but the problem is that I had not specified GMT, and so it was using local time, which changes to 'save daylight. This is demonstrated below: unclass(as.POSIXct(1975-04-27,tz=GMT))[1]-unclass(as.POSIXct(1975-04-28,tz=GMT))[1] [1]

Re: [R] bug in difftime with as.POSIXct

2008-01-27 Thread Dan Kelley
Thanks, that article is very helpful. D. Gabor Grothendieck wrote: Read relevant article in R News 4/1. -- View this message in context: http://www.nabble.com/bug-in-difftime-with-as.POSIXct-tp15122749p15125302.html Sent from the R help mailing list archive at Nabble.com.

Re: [R] access data inside package

2008-01-20 Thread Dan Kelley
The technique d - get(d, pos=globalenv()) doesn't work for me. It just says that it cannot get d, even though I have a data/d.rda file. Do I have to do something special with namespaces, to find it? PS. a possibly-related link is as follows.

Re: [R] access data inside package

2008-01-20 Thread Dan Kelley
Yes, data() works, but then I have this warning from R CMD check on my package, so I think I should not be doing it that way. Benilton Carvalho wrote: have you tried data() instead? b -- View this message in context:

Re: [R] access data inside package

2008-01-20 Thread Dan Kelley
My R CMD check gives me fit.tide: no visible binding for global variable ‘tideconst’ when I do load(paste(system.file(package=oce),data/tidesetup.rda,sep=/)) ... try to use tideconst ... where tidesetup.rda holds, among other things, a variable named tideconst. I guess I can see why

Re: [R] access data inside package

2008-01-20 Thread Dan Kelley
, pos=globalenv()) Uwe Ligges Dan Kelley wrote: Yes, data() works, but then I have this warning from R CMD check on my package, so I think I should not be doing it that way. Benilton Carvalho wrote: have you tried data() instead? b

[R] how to make read-only data frames?

2008-01-11 Thread Dan Kelley
QUESTION: is there a way to make objects (e.g. data frames) read-only? BACKGROUND: I am writing some functions that use a data frame (frequencies of tidal constituents) that I want to be read-only. I can see how to accomplish this within a single function (just define the data in the function),

Re: [R] question on axis box with asp=1

2007-10-23 Thread Dan Kelley
to the whole R-help list (I hope that is correct protocol), in case anyone later on comes across the question and wants to know how it proceeded. Again, Uwe, thanks for the advice. Dan Kelley. On 2007-10-23, at 8:36 AM, Uwe Ligges wrote: Why don't you create a device that is approximately squared

[R] question on axis box with asp=1

2007-10-22 Thread Dan Kelley
I've been using (and loving) R for quite a while now, but I have to admit that something simple is still stumping me. The question is how I can control the box within which a plot is drawn, in cases where I'm controlling the aspect ratio with the asp argument. The problem comes up in pdf()