Re: [Rd] Registering native routines

2013-02-25 Thread Terry Therneau
That was the correct direction: I changed the earler line to "routines <- list(Ccoxfit5a, 
..." and the the later to  .C(routnines[[1]]) and now it works as desired.


Terry T.

On 02/23/2013 03:09 AM, Duncan Murdoch wrote:

On 13-02-22 2:59 PM, Terry Therneau wrote:

I'm working on registering all the routines in the survival package, per a 
request from
R-core.  Two questions:

1. In the coxph routine I have this type of structure:
   if (survival has 2 columns) routines <- c("coxfit5_a", "coxfit5_b", 
"coxfit5_c")
  else routines <- c("agfit5_a",  "agfit5_b",  
"agfit5_c")

.

  .C(routines[1], arg1, etc

I tried replacing "routines" with a vector of native symbol references, but it doesn't 
work


Error in .C(routines[1], as.integer(n), as.integer(nvar), as.double(y),  :
first argument must be a string (of length 1) or native symbol reference


I imagine routines is a list in this case, so you should be using routines[[1]] to 
extract the element, rather than subsetting the list.


Duncan Murdoch


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


[Rd] png() problem with R-devel on Mac

2013-02-25 Thread Dan Tenenbaum
> png(tempfile())
Error in .External(C_Quartz, "png", path.expand(filename), width, height,  :
  Incorrect number of arguments (12), expecting 11 for 'Quartz'
> sessionInfo()
R Under development (unstable) (2013-02-24 r62054)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

> capabilities()
jpeg  png tifftcltk  X11 aqua http/ftp  sockets
TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
  libxml fifo   clediticonv  NLS  profmemcairo
TRUE TRUE TRUE TRUE TRUE TRUE TRUE

Thanks,
Dan

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


Re: [Rd] Recommended way to call/import functions from a Suggested package

2013-02-25 Thread Davor Cubranic
On 2013-02-22, at 10:23 PM, Berwin A Turlach wrote:

>> On Feb 22, 2013, at 6:39 PM, David Winsemius wrote:
> [...]
>>> I've always wondered: How does lattice manage to use grid functions
>>> without putting them on the search path?
> 
> Because lattice imports the grid package and has a NAMESPACE (as have
> all packages nowadays):
> 
> R> packageDescription("lattice")
> Package: lattice
> Version: 0.20-10
> Date: 2012/08/21
> [...]
> Suggests: grid, KernSmooth, MASS
> Imports: grid, grDevices, graphics, stats, utils, methods
> [...]
> 

Having an "Imports" line in the DESCRIPTION doesn't actually import anything. 
You have to have an "import" or "importsFrom" in the NAMESPACE. Which, sure 
enough, Lattice has:

import(grid)
BTW, I noticed Lattice lists grid in both "Imports" and "Suggests". This seems 
contradictory, because "Imports" are supposed to be packages that are required 
while "Suggests" are optional.

> 
>> Neither can the R interpreter find it. But it's clearly available if
>> you ask nicely:
>> 
>>> grid::grid.text
> 
> This will always work, whether the grid package is loaded/attached or
> not:
[...]

This actually loads the package, as described in R-exts: "Evaluating foo::f 
will cause package foo to be loaded, but not attached, if it was not loaded 
already". 

See the example below, and notice that "grid" is present in the second call to 
sessionInfo:

> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base 
> grid::grid.layout
function (nrow = 1, ncol = 1, widths = unit(rep(1, ncol), "null"), 
heights = unit(rep(1, nrow), "null"), default.units = "null", 
respect = FALSE, just = "centre") 
{
if (!is.unit(widths)) 
widths <- unit(widths, default.units)
if (!is.unit(heights)) 
heights <- unit(heights, default.units)
valid.layout(nrow, ncol, widths, heights, respect, just)
}


> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] C

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

loaded via a namespace (and not attached):
[1] grid_2.15.2

Davor
[[alternative HTML version deleted]]

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


Re: [Rd] Recommended way to call/import functions from a Suggested package

2013-02-25 Thread Davor Cubranic
I haven't gotten any complaints from "R CMD check" when I used Simon's 
suggestion, even with "--as-cran" flag. Hadley's suggestion to use 'require' 
also works, and its side-effect of attaching the other package can in some 
applications be seen by the end user as a nice bonus, so I'll probably have to 
decide on a case-by-case basis which method to use.

On the other hand, conditional import fails the check with "Namespace 
dependency not required: 'foo'", if 'foo' is only listed in the Suggests. 
Putting it in Imports gets rid of the warning, but then I don't need to 
conditionally import it any more. :-)

To summarize, it appears that the only way to call functions from a suggested 
package is by using either 'require' (which will dynamically attach it) or the 
double colon method. Is this something that should be mentioned in R-exts?

Davor


On 2013-02-22, at 8:40 PM, Hadley Wickham wrote:

> 
> On Friday, February 22, 2013, Simon Urbanek wrote:
> 
> On Feb 22, 2013, at 9:13 PM, Hadley Wickham wrote:
> 
> > Hi Davor,
> >
> > To the best of my knowledge, there's only one way to use functions
> > from a suggested package: with require:
> >
> > if (require("suggested_package")) {
> >  function_from_suggested_package()
> > } else {
> >  stop("suggested package not installed")
> > }
> >
> > Unfortunately I don't think there's any way to use a suggested package
> > without polluting the search path.
> >
> 
> Why -- wouldn't
> 
> if (is.function(try(foo::bar, silent=TRUE))) {
>   foo::bar(...)
> }
> 
> do the job?
> 
> 
>  I may be misremembering, but I think r cmd check complains about that.
> 
> Hadley
> 
> 
> -- 
> Chief Scientist, RStudio
> http://had.co.nz/


[[alternative HTML version deleted]]

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


Re: [Rd] Recommended way to call/import functions from a Suggested package

2013-02-25 Thread Hadley Wickham
> To summarize, it appears that the only way to call functions from a
> suggested package is by using either 'require' (which will dynamically
> attach it) or the double colon method. Is this something that should be
> mentioned in R-exts?

Except the double colon method doesn't work (i.e. does not pass R CMD
check) unless you also import the package, which means it's no longer
just a suggestion - it must always be installed.

A simple test case (attached DESCRIPTION and R/test.r) yields this
warning on R CMD check:

* checking for unstated dependencies in R code ... WARNING
'::' or ':::' import not declared from: 'MASS'
See the information on DESCRIPTION files in the chapter 'Creating R
packages' of the 'Writing R Extensions' manual.

Hadley

-- 
Chief Scientist, RStudio
http://had.co.nz/
__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Recommended way to call/import functions from a Suggested package

2013-02-25 Thread Martin Morgan

On 02/25/2013 01:28 PM, Hadley Wickham wrote:

To summarize, it appears that the only way to call functions from a
suggested package is by using either 'require' (which will dynamically
attach it) or the double colon method. Is this something that should be
mentioned in R-exts?


Except the double colon method doesn't work (i.e. does not pass R CMD
check) unless you also import the package, which means it's no longer
just a suggestion - it must always be installed.

A simple test case (attached DESCRIPTION and R/test.r) yields this
warning on R CMD check:

* checking for unstated dependencies in R code ... WARNING
'::' or ':::' import not declared from: 'MASS'
See the information on DESCRIPTION files in the chapter 'Creating R
packages' of the 'Writing R Extensions' manual.


haven't been following fully, but loadNamespace rather than require, with 
Suggests: MASS in DESCRIPTION ?


f = function() {
ok <- tryCatch({
loadNamespace("MASS")
TRUE
}, error=function(...) FALSE)

if (ok) {
MASS::huber(1:10)
cat("OK\n")
}
}

loadNamespaces loads but does not attach the package. Suggests: is enough to 
quieten the warning with


~/tmp$ R --version
R Under development (unstable) (2013-02-21 r62017) -- "Unsuffered Consequences"

This is consistent with RShowDoc("R-exts") section 1.1.1

  Namespaces accessed by the ‘::’ and ‘:::’ operators must be listed here, or 
in ‘Suggests’ or ‘Enhances’ (see below).


Martin



Hadley



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




--
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793

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


Re: [Rd] Recommended way to call/import functions from a Suggested package

2013-02-25 Thread Hadley Wickham
> loadNamespaces loads but does not attach the package. Suggests: is enough to
> quieten the warning with
>
> ~/tmp$ R --version
> R Under development (unstable) (2013-02-21 r62017) -- "Unsuffered
> Consequences"
>
> This is consistent with RShowDoc("R-exts") section 1.1.1
>
>   Namespaces accessed by the ‘::’ and ‘:::’ operators must be listed here,
> or in ‘Suggests’ or ‘Enhances’ (see below).

I guess that's changed since I last tried it.  (My reproducible
example forgot to include MASS in the Suggests :/ )

Thanks!

Hadley

-- 
Chief Scientist, RStudio
http://had.co.nz/

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


Re: [Rd] Recommended way to call/import functions from a Suggested package

2013-02-25 Thread Davor Cubranic
I don't see any warnings if MASS is listed in Suggests in the DESCRIPTION.

Davor

On 2013-02-25, at 1:28 PM, Hadley Wickham wrote:

>> To summarize, it appears that the only way to call functions from a
>> suggested package is by using either 'require' (which will dynamically
>> attach it) or the double colon method. Is this something that should be
>> mentioned in R-exts?
> 
> Except the double colon method doesn't work (i.e. does not pass R CMD
> check) unless you also import the package, which means it's no longer
> just a suggestion - it must always be installed.
> 
> A simple test case (attached DESCRIPTION and R/test.r) yields this
> warning on R CMD check:
> 
> * checking for unstated dependencies in R code ... WARNING
> '::' or ':::' import not declared from: 'MASS'
> See the information on DESCRIPTION files in the chapter 'Creating R
> packages' of the 'Writing R Extensions' manual.
> 
> Hadley
> 
> -- 
> Chief Scientist, RStudio
> http://had.co.nz/
> 

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