[Rd] Displaying database records returned from postgresql to R through Java

2014-07-21 Thread Jason Donnald
Hi All,

I have a R script which returns a set of records from the postgresql to the
Java program and I want to print those records in Java.My script is like
this:


library(RPostgreSQL)
fnct1 <- function()
 {

drv <- dbDriver("PostgreSQL")
r <- dbConnect(drv, host='local', port='1234',dbname='db',
user='user', password='pwd')
rs <- dbSendQuery(r,"select * from table1 where colm1 = 'val1'")
temp <- fetch(rs,n=-1)
return(temp)
 }


My Java code is :

c.parseAndEval("try(source(\"scpt.R\"),silent=TRUE)");
res =  c.parseAndEval("try(fnct1(), silent=TRUE)");
System.out.println("table names are:"+ res);

When I am printing res above it is displaying

`table names are:org.rosuda.REngine.REXPGenericVector@681a9515+[1]named`

as output. When I do something like `.asString()` or  inside the
`System.out.println()` above then it throws error. How can I print or
access each record returned by R to Java?

*NOTE:* When I am running the same script file from R itself then R is
displaying some 10 records but when I am trying through Java then nothing
is getting displayed

Regards,
Jason

[[alternative HTML version deleted]]

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


[Rd] Multiple versions of data in a package

2014-07-21 Thread Chris Wallace

Dear R-devel,

I am writing for help on how I should include parallel sets of data in 
my package.


Brief summary: I am new to using data within packages.  I want a user to 
be able to specify one of two alternative versions of within-package 
datasets to use, and I want to load just that one.  I have a solution 
that works, but it doesn't seem as simple as it should be from a user's 
point of view, nor does it seem robust to errors.  What should I do better?


More details:

My package is a relatively simple set of plotting functions, that plot 
user supplied data across a number of SNPs from their experiment, and 
annotates the plot using some external data.  For example, the user supplies


SNP value
A 2
B 1.2
C 7.8

etc

The external datasets will allow me to look up the location of SNPs A, 
B, C, ... on the human genome so the user's data can be plotted in 
relation to that map, to annotate the position of local genes etc.  My 
problem is that there is no single map of the genome, so I can prepare 
external data with the positions of SNPs and genes in version 36 or 37.  
To allow this, my data/ directory contains


snps_37.Rdata, snps_36.RData, genes_37.RData, genes_36.RData

the objects in these files are called, respectively,

snps, snps, genes, genes

Therefore, a user types

> data(snps_37)
> data(genes_37)

or

> data(snps_36)
> data(genes_36)

to set up build 36 or build 37 and then my functions need only use the 
object names snps or genes, and all is fine.  But, this doesn't seem 
like a good solution.  What if a user has snps_36 and genes_37 loaded?  
What if they have an object named snps in their working environment 
called snps?  Alternatively, I could load all datasets and they could 
pass an argument "build" to my functions, but these are large datasets, 
and I don't want to use time and memory loading both versions when I 
expect any individual user to pick a single version and stick with it.


Can anyone suggest how else I might proceed?

Thank you,

Chris




--
JDRF/WT Diabetes & Inflammation Laboratory (DIL),
NIHR Cambridge Biomedical Research Centre,
Cambridge Institute for Medical Research,
University of Cambridge

Website:http://www-gene.cimr.cam.ac.uk/staff/wallace
DIL Website:http://www-gene.cimr.cam.ac.uk

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


[Rd] Question on Code snippet semantics

2014-07-21 Thread Mick Jordan

I came across this code in library.R

package <- as.character(substitute(package))

where package is the first argument to the "library" function.

I've been racking my brains to understand why this is not just an 
elaborate (and ineffcient) way to write:


package <- "package"

E.g.

> package <- as.character(substitute(package))
> package
[1] "package"
>

Thanks
Mick Jordan

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


Re: [Rd] Question on Code snippet semantics

2014-07-21 Thread Marc Schwartz

On Jul 21, 2014, at 10:07 AM, Mick Jordan  wrote:

> I came across this code in library.R
> 
> package <- as.character(substitute(package))
> 
> where package is the first argument to the "library" function.
> 
> I've been racking my brains to understand why this is not just an elaborate 
> (and ineffcient) way to write:
> 
> package <- "package"
> 
> E.g.
> 
> > package <- as.character(substitute(package))
> > package
> [1] "package"
> >
> 
> Thanks
> Mick Jordan


Frequently used in a function body, where the function author wants the 
argument to be passed as an object name, rather than a character vector, or 
perhaps both, as is the case with library() and require().

For example:

test <- function(x) {as.character(substitute(x))}

# Quoted, passing "MyPackage" as a character vector
> test("MyPackage")
[1] "MyPackage"


# Not quoted, passing the object MyPackage
> test(MyPackage)
[1] "MyPackage"


In both cases, the argument passed as 'x' can then be used within the function 
as a character vector, rather than as the object itself.

Regards,

Marc Schwartz

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


Re: [Rd] Question on Code snippet semantics

2014-07-21 Thread William Dunlap
subsitute(expr), with only one argument, is only useful inside of a
function and then only when the expression, expr, involves an argument
to the function.  Then the unevaluated actual arguments to the
function are substituted into the [unevaluated] expression.

E.g.,
   f <- function(x, y=stop("y is required"), z=log(-1)) {
  substitute(y + z)
   }
   f(1)
   # stop("y is required") + log(-1)
   f(1,sqrt(-1),log(1:10))
   # sqrt(-1) + log(1:10)

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Mon, Jul 21, 2014 at 8:07 AM, Mick Jordan  wrote:
> I came across this code in library.R
>
> package <- as.character(substitute(package))
>
> where package is the first argument to the "library" function.
>
> I've been racking my brains to understand why this is not just an elaborate
> (and ineffcient) way to write:
>
> package <- "package"
>
> E.g.
>
>> package <- as.character(substitute(package))
>> package
> [1] "package"
>>
>
> Thanks
> Mick Jordan
>
> __
> 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


[Rd] create R package include Fortran source code.

2014-07-21 Thread yiqun yang
Hello, all

I am building a R package using Fortran source code. The Fortran code is a
subroutine. I can use "R CMD SHLIB  bar.f -o bar.o" to create the shared
library. For the R package, I put the fortran file in the src/ and I use R
code as follows:

".First.lib"<-function(libname,pkgname){library.dynam("barpkg",pkgname,libname)}
barfun<-function(n,x){
  .Fortran("bar",as.integer(n),as.double(x))
}
package.skeleton(name="barpkg",list=c("barfun"))
--
I can build with "R CMD build barpkg", when I check the package with "R CMD
check barpkg", there is an error,

** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
Error in inDL(x, as.logical(local), as.logical(now), ...) :
  unable to load shared object
'c:/Users/emily/Desktop/rtest/barpkg.Rcheck/barpkg/libs/i386/bar.dll':
  LoadLibrary failure:  %1 is not a valid Win32 application.

Error: loading failed
Execution halted
*** arch - x64
ERROR: loading failed for 'i386'

I don't know how to fix this error. Can anyone help me with this?

Thanks.
-Emily

[[alternative HTML version deleted]]

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


[Rd] Licence for datasets in a R-package

2014-07-21 Thread Gionata Bocci
 Dear List,

   I am building a R package which collects ecological data about plant
species from both remote (web) databases and locally stored rda files
(datasets): these "local rda files" are derived from publicly available
databases for which no "official" licenses are provided; I was told by the
creators of these databases that users can use such data provided that the
correct bibliographic reference is always used (the package is already
reminding the users about the correct citation(s) to use). I thought a
CC-by licence would suit this need, thus I am posting here to ask if:

 1) It is possible to distribute these datasets as rda files within my
package (which will be released as GPL=>2, thus two different licences will
be needed for the package)
 2) If a CC-by licence for these datasets could be included in the
DESCRIPTION file, using something like "License: CC-by datasets.rda" for
each rda file (this is based on this stackoverflow thread
, but CC-by is not among the LICENSES
cited in http://www.r-project.org/Licenses/): I've already tried to do
this, but, as a consequence, the "R check" raises a warning.

   I am aware that this is more a licensing issue then a programming
problem, but I went through the R FAQ, "Writing R Extensions" and R-devel
but was not able to sort this problem out (so, please ignore this post if
you find it OT).
   I hope the question is not too messy (this is my first time on R-devel).
   Many thanks for any help you may provide,


Gionata Bocci.

[[alternative HTML version deleted]]

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


Re: [Rd] create R package include Fortran source code.

2014-07-21 Thread Duncan Murdoch

On 21/07/2014 12:10 PM, yiqun yang wrote:

Hello, all

I am building a R package using Fortran source code. The Fortran code is a
subroutine. I can use "R CMD SHLIB  bar.f -o bar.o" to create the shared
library. For the R package, I put the fortran file in the src/ and I use R
code as follows:

".First.lib"<-function(libname,pkgname){library.dynam("barpkg",pkgname,libname)}
barfun<-function(n,x){
   .Fortran("bar",as.integer(n),as.double(x))
}
package.skeleton(name="barpkg",list=c("barfun"))
--
I can build with "R CMD build barpkg", when I check the package with "R CMD
check barpkg", there is an error,

** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
Error in inDL(x, as.logical(local), as.logical(now), ...) :
   unable to load shared object
'c:/Users/emily/Desktop/rtest/barpkg.Rcheck/barpkg/libs/i386/bar.dll':
   LoadLibrary failure:  %1 is not a valid Win32 application.


You will see more information in the files in the barpkg.Rcheck 
directory created during the check.  You can see some of those messages 
on the screen if you do an explicit INSTALL.


I'd guess that the compile failed, but can't guess why.

Duncan Murdoch




Error: loading failed
Execution halted
*** arch - x64
ERROR: loading failed for 'i386'

I don't know how to fix this error. Can anyone help me with this?

Thanks.
-Emily

[[alternative HTML version deleted]]

__
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] Licence for datasets in a R-package

2014-07-21 Thread Duncan Murdoch

On 21/07/2014 12:17 PM, Gionata Bocci wrote:

  Dear List,

I am building a R package which collects ecological data about plant
species from both remote (web) databases and locally stored rda files
(datasets): these "local rda files" are derived from publicly available
databases for which no "official" licenses are provided; I was told by the
creators of these databases that users can use such data provided that the
correct bibliographic reference is always used (the package is already
reminding the users about the correct citation(s) to use). I thought a
CC-by licence would suit this need, thus I am posting here to ask if:

  1) It is possible to distribute these datasets as rda files within my
package (which will be released as GPL=>2, thus two different licences will
be needed for the package)
  2) If a CC-by licence for these datasets could be included in the
DESCRIPTION file, using something like "License: CC-by datasets.rda" for
each rda file (this is based on this stackoverflow thread
, but CC-by is not among the LICENSES
cited in http://www.r-project.org/Licenses/): I've already tried to do
this, but, as a consequence, the "R check" raises a warning.

I am aware that this is more a licensing issue then a programming
problem, but I went through the R FAQ, "Writing R Extensions" and R-devel
but was not able to sort this problem out (so, please ignore this post if
you find it OT).
I hope the question is not too messy (this is my first time on R-devel).
Many thanks for any help you may provide,


If you are not distributing the package to anyone else, you can ignore 
the warning about the bad license field.


If you plan to distribute it on a public repository, you should ask the 
policies of the repository to find out what to do about this. CRAN 
policies are listed at 
http://cran.r-project.org/web/packages/policies.html.  There's a link 
from there to the list of acceptable licenses, and it includes some CC 
licenses.


If some parts of the package are licensed one way and others are 
licensed in another way, you'll probably need a COPYRIGHTS file to 
describe it.


Other repositories (e.g. Bioconductor, Github) presumably have their own 
policies on this, but I don't know where to find those.


Duncan Murdoch

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


Re: [Rd] Licence for datasets in a R-package

2014-07-21 Thread Gábor Csárdi
On Mon, Jul 21, 2014 at 12:49 PM, Duncan Murdoch
 wrote:
[...]
> If you are not distributing the package to anyone else, you can ignore the
> warning about the bad license field.
>
> If you plan to distribute it on a public repository, you should ask the
> policies of the repository to find out what to do about this. CRAN policies
> are listed at http://cran.r-project.org/web/packages/policies.html.  There's
> a link from there to the list of acceptable licenses, and it includes some
> CC licenses.
>
> If some parts of the package are licensed one way and others are licensed in
> another way, you'll probably need a COPYRIGHTS file to describe it.

In practice, CRAN maintainers do not allow multiple licenses for parts
of the same package. At least they did not for my package a couple of
months ago.

> Other repositories (e.g. Bioconductor, Github) presumably have their own
> policies on this, but I don't know where to find those.

At Github, they do not care, you can do whatever you want (as long as
it is legal, I guess).

Gabor

[...]

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


Re: [Rd] Licence for datasets in a R-package

2014-07-21 Thread Gabor Grothendieck
On Mon, Jul 21, 2014 at 12:54 PM, Gábor Csárdi  wrote:
> In practice, CRAN maintainers do not allow multiple licenses for parts
> of the same package. At least they did not for my package a couple of
> months ago.
>

If that is the case then you could put your data files in a separate
package from the code with one depending on the other.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

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


Re: [Rd] Licence for datasets in a R-package

2014-07-21 Thread Gábor Csárdi
On Mon, Jul 21, 2014 at 1:56 PM, Gabor Grothendieck
 wrote:
> On Mon, Jul 21, 2014 at 12:54 PM, Gábor Csárdi  wrote:
>> In practice, CRAN maintainers do not allow multiple licenses for parts
>> of the same package. At least they did not for my package a couple of
>> months ago.
>>
>
> If that is the case then you could put your data files in a separate
> package from the code with one depending on the other.

Yes, and sometimes this even makes sense, as the data does not change often.

This was, however, a package with several data sets, accompanying a
book. So this would have been quite cumbersome.

Gabor

>
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com

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


Re: [Rd] create R package include Fortran source code.

2014-07-21 Thread yiqun yang
Thank you for your reply.
First I try "R CMD INSTALL barpkg", then it gives similiar things:
-
* installing *source* package 'barpkg' ...
** libs

*** arch - i386
cygwin warning:
  MS-DOS style path detected: C:/PROGRA~1/R/R-31~1.0/etc/i386/Makeconf
  Preferred POSIX equivalent is:
/cygdrive/c/PROGRA~1/R/R-31~1.0/etc/i386/Makeconf
  CYGWIN environment variable option "nodosfilewarning" turns off this
warning.
  Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
gfortran -m32 -O3  -mtune=core2 -c bar.f -o bar.o
gcc -m32 -shared -s -static-libgcc -o barpkg.dll tmp.def bar.o
-Ld:/RCompile/CRANpkg/extralibs64/local/lib/i386
-Ld:/RCompile/CRANpkg/extralibs64/local/lib -lgfortran
-LC:/PROGRA~1/R/R-31~1.0/bin/i386 -lR
cygwin warning:
  MS-DOS style path detected: C:/PROGRA~1/R/R-31~1.0/etc/i386/Makeconf
  Preferred POSIX equivalent is:
/cygdrive/c/PROGRA~1/R/R-31~1.0/etc/i386/Makeconf
  CYGWIN environment variable option "nodosfilewarning" turns off this
warning.
  Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
installing to C:/Users/emily/Desktop/rtest/barpkg.Rcheck/barpkg/libs/i386

*** arch - x64
cygwin warning:
  MS-DOS style path detected: C:/PROGRA~1/R/R-31~1.0/etc/x64/Makeconf
  Preferred POSIX equivalent is:
/cygdrive/c/PROGRA~1/R/R-31~1.0/etc/x64/Makeconf
  CYGWIN environment variable option "nodosfilewarning" turns off this
warning.
  Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
gfortran -m64 -O2  -mtune=core2 -c bar.f -o bar.o
gcc -m64 -shared -s -static-libgcc -o barpkg.dll tmp.def bar.o
-Ld:/RCompile/CRANpkg/extralibs64/local/lib/x64
-Ld:/RCompile/CRANpkg/extralibs64/local/lib -lgfortran
-LC:/PROGRA~1/R/R-31~1.0/bin/x64 -lR
cygwin warning:
  MS-DOS style path detected: C:/PROGRA~1/R/R-31~1.0/etc/x64/Makeconf
  Preferred POSIX equivalent is:
/cygdrive/c/PROGRA~1/R/R-31~1.0/etc/x64/Makeconf
  CYGWIN environment variable option "nodosfilewarning" turns off this
warning.
  Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
installing to C:/Users/emily/Desktop/rtest/barpkg.Rcheck/barpkg/libs/x64
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
Error in inDL(x, as.logical(local), as.logical(now), ...) :
  unable to load shared object
'C:/Users/emily/Desktop/rtest/barpkg.Rcheck/barpkg/libs/i386/bar.dll':
  LoadLibrary failure:  %1 is not a valid Win32 application.

Error: loading failed
Execution halted
*** arch - x64
ERROR: loading failed for 'i386'
* removing 'C:/Users/emily/Desktop/rtest/barpkg.Rcheck/barpkg'

2) I don't know how to check the "compile" problem. I just try to
"dyn.load" the shared object in /src-i386 and /src-x64 in the package, and
they both work well.

I am guessing there is some error in the R language.
".First.lib"<-function(libname,pkgname){library.dynam("barpkg",pkgname,
libname)}
barfun<-function(n,x){
   .Fortran("bar",as.integer(n),as.double(x))
}
package.skeleton(name="barpkg",list=c("barfun"))

I am not sure about this part. Can anyone give me some suggestion?
I appreciate that very much.

-Emily


On Mon, Jul 21, 2014 at 11:42 AM, Duncan Murdoch 
wrote:

> On 21/07/2014 12:10 PM, yiqun yang wrote:
>
>> Hello, all
>>
>> I am building a R package using Fortran source code. The Fortran code is a
>> subroutine. I can use "R CMD SHLIB  bar.f -o bar.o" to create the shared
>> library. For the R package, I put the fortran file in the src/ and I use R
>> code as follows:
>>
>> ".First.lib"<-function(libname,pkgname){library.dynam("barpkg",pkgname,
>> libname)}
>> barfun<-function(n,x){
>>.Fortran("bar",as.integer(n),as.double(x))
>> }
>> package.skeleton(name="barpkg",list=c("barfun"))
>> 
>> --
>> I can build with "R CMD build barpkg", when I check the package with "R
>> CMD
>> check barpkg", there is an error,
>>
>> ** R
>> ** preparing package for lazy loading
>> ** help
>> *** installing help indices
>> ** building package indices
>> ** testing if installed package can be loaded
>> *** arch - i386
>> Error in inDL(x, as.logical(local), as.logical(now), ...) :
>>unable to load shared object
>> 'c:/Users/emily/Desktop/rtest/barpkg.Rcheck/barpkg/libs/i386/bar.dll':
>>LoadLibrary failure:  %1 is not a valid Win32 application.
>>
>
> You will see more information in the files in the barpkg.Rcheck di

Re: [Rd] create R package include Fortran source code.

2014-07-21 Thread Charles Berry
yiqun yang  gmail.com> writes:

> 
> Thank you for your reply.
> First I try "R CMD INSTALL barpkg", then it gives similiar things:
>
-

[deleted]

-
> 2) I don't know how to check the "compile" problem. I just try to
> "dyn.load" the shared object in /src-i386 and /src-x64 in the package, and
> they both work well.
> 
> I am guessing there is some error in the R language.
> ".First.lib"<-function(libname,pkgname){library.dynam("barpkg",pkgname,
> libname)}
> barfun<-function(n,x){
>.Fortran("bar",as.integer(n),as.double(x))
> }
> package.skeleton(name="barpkg",list=c("barfun"))
> 
> I am not sure about this part. Can anyone give me some suggestion?



?.First.lib

refers to the base-defunct {base} help page which says:

[...]

# Defunct in 2.14.0
.First.lib(lib, pkg)

[...]
Details

Some of these have stubs which report that they are defunct, but most have
been removed completely (apart from being documented here).
[...]



So, don't use .First.lib.

Try a useDynLib directive in your NAMESPACE file.

You probably need to spend some time pondering 

  Writing R Extensions

especially section

1.5.4 useDynLib

HTH,

Chuck

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