[Rd] S4 coercion responsibility

2008-09-15 Thread Paul Gilbert
Should functions or the user be responsible for coercing an S4 object 
argument containing the proper object (and thus should below be 
considered a bug in the packages or not)?


The example is  with RSQLite but the same thing happens with RMySQL, and 
other DBI packages.


> library("RSQLite")  Loading required package: DBI
> m <- dbDriver("SQLite")
> con <- dbConnect(m)
> setClass("SQLConPlus", contains=c("SQLiteConnection","integer"))
[1] "SQLConPlus"
> conPlus <- new("SQLConPlus", con, 1)
> dbListTables(con)
character(0)
> dbListTables(conPlus)
Error in sqliteExecStatement(con, statement, bind.data) :
RS-DBI driver: (invalid dbManager handle)
> dbListTables(as(conPlus, "SQLiteConnection"))
character(0)
>

The problem is happening in sqliteExecStatement which does
  conId <- as(con, "integer")
but con only *contains* an SQLiteConnection and the other integer
causes confusion. If the line were
  conId <- as(as(con, "SQLiteConnection"), "integer")
everything works.

I can work around this, but I am curious where  responsibility for this 
coercion should be.


Paul Gilbert


La version française suit le texte anglais.



This email may contain privileged and/or confidential in...{{dropped:26}}

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Including data in package for use by C functions

2008-09-15 Thread Ernest Turro
How should one go about including data files for use by some C  
function in an R package? The data subdirectory is for additional data  
files the package makes available for loading from R, not C, and  
including the files in some other directory is no good because non- 
standard directories are removed when building the package.


Thanks,

E

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Including data in package for use by C functions

2008-09-15 Thread Duncan Murdoch

On 9/15/2008 10:18 AM, Ernest Turro wrote:
How should one go about including data files for use by some C  
function in an R package? The data subdirectory is for additional data  
files the package makes available for loading from R, not C, and  
including the files in some other directory is no good because non- 
standard directories are removed when building the package.


Nonstandard directories in the "inst" subdir are moved up one level and 
kept, so that's the place to put stuff like this.


e.g. packagesrc/inst/foo becomes package/foo when the package is installed.

Duncan Murdoch

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Cross-platform function availability

2008-09-15 Thread hadley wickham
Hi all,

Is there any way to determine which functions are available on which
platforms?  For example, winProgr essBar (and related functions) are
only available on Windows, but what about tkProgressBar and
txtProgressBar?  Is there any way to figure out which functions are
only available on certain platforms, without installing R on that
platform and checking?

Thanks,

Hadley

-- 
http://had.co.nz/

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Cross-platform function availability

2008-09-15 Thread Duncan Murdoch

On 9/15/2008 11:42 AM, hadley wickham wrote:

Hi all,

Is there any way to determine which functions are available on which
platforms?  For example, winProgr essBar (and related functions) are
only available on Windows, but what about tkProgressBar and
txtProgressBar?  Is there any way to figure out which functions are
only available on certain platforms, without installing R on that
platform and checking?


Generally I think the only reliable way is to look at the source. 
Things in "windows" subdirs, or marked off with "#ifdef windows" (in Rd) 
or "#ifdef Win32" (in C) are for windows only.  Probably our 
documentation should point out when something is platform-specific, and 
frequently it does, but I don't think it is completely consistent in this.


Duncan

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Cross-platform function availability

2008-09-15 Thread Greg Snow
I think it is a little more complex than just installing and checking.  
tkProgressBar uses tcltk which works on the major platforms (unix/linux, mac, 
windows), but only if tk is installed and available.  I believe that on mac tk 
is only available if X11 is used and if I remember correctly, if R is run by 
clicking an icon, then X11 is not used (but it is if run from a command 
window).  So checking may say it does not work (when it does in a different 
way), or that it does work, but the end user may not get it to work.

I believe that txtProgressBar works on any version that can produce text (all 
that I know of), but you may get some funny results if output is being sent 
directly to a file.

More generally, from the packages link on your favorite CRAN mirror, there is a 
link to package test results that show the results of testing the packages on 
different platforms that may give some idea if the function works on the tested 
platforms (if the documentation for the function has examples not wrapped in 
dontrun commands or other tests).

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[EMAIL PROTECTED]
(801) 408-8111



> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of hadley wickham
> Sent: Monday, September 15, 2008 9:43 AM
> To: r-devel@r-project.org
> Subject: [Rd] Cross-platform function availability
>
> Hi all,
>
> Is there any way to determine which functions are available
> on which platforms?  For example, winProgr essBar (and
> related functions) are only available on Windows, but what
> about tkProgressBar and txtProgressBar?  Is there any way to
> figure out which functions are only available on certain
> platforms, without installing R on that platform and checking?
>
> Thanks,
>
> Hadley
>
> --
> http://had.co.nz/
>
> __
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] S4 coercion responsibility

2008-09-15 Thread Seth Falcon
* On 2008-09-15 at 08:56 -0400 Paul Gilbert wrote:
> Should functions or the user be responsible for coercing an S4 object 
> argument containing the proper object (and thus should below be 
> considered a bug in the packages or not)?
>
> The example is  with RSQLite but the same thing happens with RMySQL, and 
> other DBI packages.
>
> > library("RSQLite")  Loading required package: DBI
> > m <- dbDriver("SQLite")
> > con <- dbConnect(m)
> > setClass("SQLConPlus", contains=c("SQLiteConnection","integer"))
> [1] "SQLConPlus"
> > conPlus <- new("SQLConPlus", con, 1)
> > dbListTables(con)
> character(0)
> > dbListTables(conPlus)
> Error in sqliteExecStatement(con, statement, bind.data) :
> RS-DBI driver: (invalid dbManager handle)
> > dbListTables(as(conPlus, "SQLiteConnection"))
> character(0)
> >
>
> The problem is happening in sqliteExecStatement which does
>   conId <- as(con, "integer")
> but con only *contains* an SQLiteConnection and the other integer
> causes confusion. If the line were
>   conId <- as(as(con, "SQLiteConnection"), "integer")
> everything works.
>
> I can work around this, but I am curious where  responsibility for this 
> coercion should be.

Well, you've created a class that is-a SQLiteConnection *and* is-a
integer.  The fact that the as() method dispatch doesn't match that of
SQLiteConnection should really be that surprising.

I don't see how this could be the responsibility of the author of the
class you've subclassed.

I would also question why SQLConPlus is extending integer.  That seems
like a very strange choice.  Why not extend SQLiteConnection and add
extra slots as you like.  The dispatch will in this case be much
easier to reason about.

+ seth

-- 
Seth Falcon | http://userprimary.net/user/

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Using R from Java

2008-09-15 Thread Lars Hansen

Hi,

Take a look at the rJava package. It includes JRI that lets you call R 
from Java. From the README:

This package contains code that is necessary to run
R as a single thread of a Java application. It provides
callback that make it possible to run R in REPL mode
thus giving the Java application full access to the
console.

Currently the API is very, very low-level, comparable
to the C level interface to R. Convenience methods for
mid to high-level are planned, but not implemented yet.

Good luck,
Lars

Marzio Sala wrote:

Hello,

I am interesting in using R from a web application, for basic statistics and
plots. The server is Java-based (tomcat).
The simplest solution is a system call that generates the text or the image,
then the servlet forwards the output. This can be done from any language,
but it is quite inelegant and slow for the initialization time.

Is there any package or approach for accessing R from a Java servlet you can
suggest?

Thanks in advance for any suggestion.

Regards,
-Marzio




__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Cross-platform function availability

2008-09-15 Thread hadley wickham
On Mon, Sep 15, 2008 at 12:06 PM, Duncan Murdoch <[EMAIL PROTECTED]> wrote:
> On 9/15/2008 11:42 AM, hadley wickham wrote:
>>
>> Hi all,
>>
>> Is there any way to determine which functions are available on which
>> platforms?  For example, winProgr essBar (and related functions) are
>> only available on Windows, but what about tkProgressBar and
>> txtProgressBar?  Is there any way to figure out which functions are
>> only available on certain platforms, without installing R on that
>> platform and checking?
>
> Generally I think the only reliable way is to look at the source. Things in
> "windows" subdirs, or marked off with "#ifdef windows" (in Rd) or "#ifdef
> Win32" (in C) are for windows only.  Probably our documentation should point
> out when something is platform-specific, and frequently it does, but I don't
> think it is completely consistent in this.

To me it seems like it would be easier to include the all functions
all on platforms, and then return an error on platforms where they
aren't supported.  The problem I'm now having is that I'm now getting
an warning when building my package because it can't link to the
documentation for winProgressBar.  Should I just ignore that warning?

Hadley



-- 
http://had.co.nz/

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Cross-platform function availability

2008-09-15 Thread Duncan Murdoch

On 9/15/2008 1:43 PM, hadley wickham wrote:

On Mon, Sep 15, 2008 at 12:06 PM, Duncan Murdoch <[EMAIL PROTECTED]> wrote:

On 9/15/2008 11:42 AM, hadley wickham wrote:


Hi all,

Is there any way to determine which functions are available on which
platforms?  For example, winProgr essBar (and related functions) are
only available on Windows, but what about tkProgressBar and
txtProgressBar?  Is there any way to figure out which functions are
only available on certain platforms, without installing R on that
platform and checking?


Generally I think the only reliable way is to look at the source. Things in
"windows" subdirs, or marked off with "#ifdef windows" (in Rd) or "#ifdef
Win32" (in C) are for windows only.  Probably our documentation should point
out when something is platform-specific, and frequently it does, but I don't
think it is completely consistent in this.


To me it seems like it would be easier to include the all functions
all on platforms, and then return an error on platforms where they
aren't supported.  The problem I'm now having is that I'm now getting
an warning when building my package because it can't link to the
documentation for winProgressBar.  Should I just ignore that warning?


 It's better not to ignore warnings. 

I'd suggest wrapping the link in "#ifdef windows" (assuming it's in an 
Rd file).


Duncan Murdoch

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Typo in cut.Rd

2008-09-15 Thread Stephen Weigand
In the \seealso section of cut.Rd, can "\pkg{hmisc}" be changed to
"\pkg{Hmisc}"?

Thanks,
Stephen

-- 
Rochester, Minn. USA

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Typo in cut.Rd

2008-09-15 Thread Duncan Murdoch

On 15/09/2008 5:45 PM, Stephen Weigand wrote:

In the \seealso section of cut.Rd, can "\pkg{hmisc}" be changed to
"\pkg{Hmisc}"?


Thanks, I'll fix it.

Duncan Murdoch

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] odesolve dynload example

2008-09-15 Thread Redding, Matthew
Hello R Developers,

This is my first foray into using c-code with R, so please forgive my
foolishness.
I had a look at the archives and did not find anything on this, so
hopefully I am not doubling up.

I have tried to use R cmd to create an object file from the odesolve
dynload example.
I am using windows and have just installed rtools, and have the latest
version of stable R (2..7.2).

This is what happened:

C:\Program Files\R\R-2.7.2\library\odesolve\dynload\c>Rcmd SHLIB mymod.c
making mymod.d from mymod.c
windres --preprocessor="gcc -E -xc -DRC_INVOKED" -I
C:/PROGRA~1/R/R-27~1.2/include  -i mymod_res.rc -o mymod_res.o
gcc  -std=gnu99  -shared -s  -o mymod.dll mymod.def mymod.o mymod_res.o
-LC:/PROGRA~1/R/R-27~1.2/bin-lR
Cannot export myderivs: symbol not found
Cannot export myjac: symbol not found
Cannot export mymod: symbol not found
mymod.o: In function `mymod':
/home/setzer/tasks/Programming_Projects/odesolve/odesolve/inst/dynload/c
/mymod.c:14: undefined reference to `GLOBAL_OFFSET_TA
BLE_'
mymod.o: In function `myderivs':
/home/setzer/tasks/Programming_Projects/odesolve/odesolve/inst/dynload/c
/mymod.c:21: undefined reference to `GLOBAL_OFFSET_TA
BLE_'
mymod.o: In function `myjac':
/home/setzer/tasks/Programming_Projects/odesolve/odesolve/inst/dynload/c
/mymod.c:30: undefined reference to `GLOBAL_OFFSET_TA
BLE_'
collect2: ld returned 1 exit status
make: *** [mymod.dll] Error 1

Any ideas what I have not got set up properly? What do I need to do to
get this firing? 
Advice appreciated.

Kind regards, 

Matt Redding
DISCLAIMER**...{{dropped:15}}

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] question in value-based color in image()

2008-09-15 Thread M.
Hello,

I have a matrix with value varying from -1 to 1.  I hope to use scaled color
based on its value to produce an image of this matrix.

Suppose I hope to label those data in [-1,-0.5] with blue, label those
[-0.5,0.8] with light blue (tone is proportional to its value) and label
those [0.8,1] with white.

How can I use image() and rgb() to achieve this?  It would be great if I can
have a color scale legend, too.

TIA,
Chris

[[alternative HTML version deleted]]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] odesolve dynload example

2008-09-15 Thread Peter Dalgaard

Redding, Matthew wrote:

Hello R Developers,

This is my first foray into using c-code with R, so please forgive my
foolishness.
I had a look at the archives and did not find anything on this, so
hopefully I am not doubling up.

I have tried to use R cmd to create an object file from the odesolve
dynload example.
I am using windows and have just installed rtools, and have the latest
version of stable R (2..7.2).

This is what happened:

C:\Program Files\R\R-2.7.2\library\odesolve\dynload\c>Rcmd SHLIB mymod.c
making mymod.d from mymod.c
windres --preprocessor="gcc -E -xc -DRC_INVOKED" -I
C:/PROGRA~1/R/R-27~1.2/include  -i mymod_res.rc -o mymod_res.o
gcc  -std=gnu99  -shared -s  -o mymod.dll mymod.def mymod.o mymod_res.o
-LC:/PROGRA~1/R/R-27~1.2/bin-lR
Cannot export myderivs: symbol not found
Cannot export myjac: symbol not found
Cannot export mymod: symbol not found
mymod.o: In function `mymod':
/home/setzer/tasks/Programming_Projects/odesolve/odesolve/inst/dynload/c
/mymod.c:14: undefined reference to `GLOBAL_OFFSET_TA
BLE_'
mymod.o: In function `myderivs':
/home/setzer/tasks/Programming_Projects/odesolve/odesolve/inst/dynload/c
/mymod.c:21: undefined reference to `GLOBAL_OFFSET_TA
BLE_'
mymod.o: In function `myjac':
/home/setzer/tasks/Programming_Projects/odesolve/odesolve/inst/dynload/c
/mymod.c:30: undefined reference to `GLOBAL_OFFSET_TA
BLE_'
collect2: ld returned 1 exit status
make: *** [mymod.dll] Error 1

Any ideas what I have not got set up properly? What do I need to do to
get this firing? 
Advice appreciated.
  
I'm a bit rusty on the windows tools, but it looks like mymod.o and  
mymod_res.rc  not being made above. Any chance that you have old 
versions lying around?


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

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel