Re: [Rd] require is to suggests as what is to imports?

2010-08-25 Thread Prof Brian Ripley

On Tue, 24 Aug 2010, Dirk Eddelbuettel wrote:



On 24 August 2010 at 15:40, Hadley Wickham wrote:
| Hi all,
|
| If a package suggests another package in its description, you can
| check it at runtime with requires.  How do you do check if a package
| is available without loading it, if you only want to access one
| function in the package namespace.

I needed this a few days ago for a small package and resorted to this:

  .packages <- as.character(installed.packages()[,1])

  [...]

  hasGputools <- function() {
  any( "gputools" == .packages )
  }

That way I get around Depends, Suggests and other thing that may impact the
running of 'R CMD check' and friends.


But thereby clobber your users with the run-time cost of 
installed.packages() (which can take several minutes on some Windows 
systems, and just took ca 12secs on my fastest Linux server with 3000 
packages installed).  If you want to take this route (is a package 
installed?), see the 'Note' on ?installed.packages for better 
alternatives.


However, that was not the question.  require() is most often used to 
answer the question 'is this package usable?' which includes checking 
that it is installed for the right architecture and has all its 
dependencies (recursively).  And Hadley's question implies both that a 
namespace can be loaded (includind DSO/DLL and dependencies) and that 
it contains/exports a specific function.


One thing many package authors have been forgetting is that on Mac OS 
X there are several sub-architectures and you need a DSO of the right 
architecture to be installed (and the default for R CMD INSTALL has 
been to install only one, and on Snow Leopard R and R.app run 
different sub-architectures).  As from 2.12.x this will apply to 
Windows too.





Dirk

--
Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com

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



--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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


Re: [Rd] save() object w/o all of the loaded environment

2010-08-25 Thread Martin Maechler
> "RL" == Roebuck,Paul L 
> on Tue, 24 Aug 2010 11:06:54 -0500 writes:

RL> I have two packages, one that does the actual work (SC)
RL> and the other a Tcl/Tk UI (SCUI) that invokes methods
RL> within the former. Within the SCUI's invocation method,
RL> I save an object returned from SC, the results of a
RL> long-running method.

RL> Now the object is completely described by the SC
RL> package. Unfortunately, any attempt to load the object
RL> (in a fresh R session) fails as below.

R> library(SC) setwd("/path/to/results/")
R> load("sc-results.rda")
RL> Loading Tcl/Tk interface ... done Error: .onLoad failed
RL> in loadNamespace() for 'SCUI', details: call:
RL> optiondb_add("*Notebook.borderWidth", 2,
RL> "widgetDefault") error: could not find function "tcl"

RL> That call (which adds resource to Tcl resource database)
RL> is made inside SCUI. Loading tcltk package removes the
RL> problem.

R> library(tcltk) load("sc-results.rda") ls()
RL> [1] "results"

RL> But I would really prefer not to need to load tcltk at
RL> all just to inspect/use the object, which contains
RL> nothing from SCUI anyway. Is there a way to strip the
RL> unwanted UI prerequisite (tcltk and SCUI) packages from
RL> the environment of the object prior/during save()?

Yes, there is:

  > fortune("Yoda")

  Evelyn Hall: I would like to know how (if) I can extract some of the 
information from the
  summary of my nlme.
  Simon Blomberg: This is R. There is no if. Only how.
 -- Evelyn Hall and Simon 'Yoda' Blomberg
R-help (April 2005)


About the "how":  I'd make use of

   ls.str() 

to start inspecting the objects there.
To help you further, we'd need more details, e.g. such
str()-like results of the things you are talking about.

Martin

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


Re: [Rd] require is to suggests as what is to imports?

2010-08-25 Thread Hadley Wickham
On Tue, Aug 24, 2010 at 3:50 PM, Prof Brian Ripley
 wrote:
> On Tue, 24 Aug 2010, Hadley Wickham wrote:
>
>> Hi all,
>>
>> If a package suggests another package in its description, you can
>> check it at runtime with requires.  How do you do check if a package
>
> Well, not really as requires() can give an error, at least until 2.12.0 is
> out.  So you need to wrap it in a try/tryCatch construct.
>
>> is available without loading it, if you only want to access one
>> function in the package namespace.
>
> You could use try/tryCatch on pkg::fun (which is what you need to do with
> require).  It is difficult (and would be fragile since the details of
> metadata are definitely subject to change without notice) to ascertain what
> a namespace will contain/export without loading it.

Ok, thanks.

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

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


Re: [Rd] require is to suggests as what is to imports?

2010-08-25 Thread Hadley Wickham
> But thereby clobber your users with the run-time cost of
> installed.packages() (which can take several minutes on some Windows
> systems, and just took ca 12secs on my fastest Linux server with 3000
> packages installed).  If you want to take this route (is a package
> installed?), see the 'Note' on ?installed.packages for better alternatives.

On that note, I wrote a version of installed.packages() which runs
quite a bit faster on my computer:

installed_packages <- function() {
  paths <- unlist(lapply(.libPaths(), dir, full.names = TRUE))
  desc <- file.path(paths, "DESCRIPTION")
  desc <- desc[file.exists(desc)]

  dcf <- lapply(desc, read.dcf, fields = c("Package", "Title", "Version"))
  packages <- as.data.frame(do.call("rbind", dcf), stringsAsFactors = FALSE)

  packages$status <- ifelse(packages$Package %in% .packages(),
"loaded", "installed")
  class(packages) <- c("packages", class(packages))
  packages[order(packages$Package), ]
}

It probably runs faster because I've eliminated some features, and
it's probably not worth spending much time optimising such a rarely
used function, but there it is for what it's worth.

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

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


Re: [Rd] require is to suggests as what is to imports?

2010-08-25 Thread Hadley Wickham
On Tue, Aug 24, 2010 at 6:55 PM, Henrik Bengtsson  
wrote:
> isPackageInstalled <- function(package, ...) {
>  path <- system.file(package=package);
>  (path != "");
> }
>
> taken from R.utils (which also has a isPackageLoaded()).

Nice quick hack (subject to caveats Brian mentions).  Thanks!

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

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


Re: [Rd] require is to suggests as what is to imports?

2010-08-25 Thread Dirk Eddelbuettel

On 25 August 2010 at 08:06, Prof Brian Ripley wrote:
| On Tue, 24 Aug 2010, Dirk Eddelbuettel wrote:
| 
| >
| > On 24 August 2010 at 15:40, Hadley Wickham wrote:
| > | Hi all,
| > |
| > | If a package suggests another package in its description, you can
| > | check it at runtime with requires.  How do you do check if a package
| > | is available without loading it, if you only want to access one
| > | function in the package namespace.
| >
| > I needed this a few days ago for a small package and resorted to this:
| >
| >   .packages <- as.character(installed.packages()[,1])
| >
| >   [...]
| >
| >   hasGputools <- function() {
| >   any( "gputools" == .packages )
| >   }
| >
| > That way I get around Depends, Suggests and other thing that may impact the
| > running of 'R CMD check' and friends.
| 
| But thereby clobber your users with the run-time cost of 
| installed.packages() (which can take several minutes on some Windows 

Yes. As that was for a so-far internal-only package that in all likelihood
will never be built on Windows for limitations of the latter platform.

Regardless, I will switch to Henrik's elegant alternative.

| systems, and just took ca 12secs on my fastest Linux server with 3000 
| packages installed).  If you want to take this route (is a package 
| installed?), see the 'Note' on ?installed.packages for better 
| alternatives.

My version of ?installed.packages has no section "Note". That is on the on
the current, released version of R.

Dirk

-- 
Dirk Eddelbuettel | e...@debian.org | http://dirk.eddelbuettel.com

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


[Rd] Trying to configure R to use acml_mp

2010-08-25 Thread szembek

Hi, I'm following up to a post I made to r-help here:
http://r.789695.n4.nabble.com/Trouble-configuring-R-to-use-ACML-tt2337193.html#a2337193

I have verified that LD_LIBRARY_PATH is set... I set it in /etc/bash.bashrc
(is that ok?) and it shows up when I echo $LD_LIBRARY_PATH I also tried
adding the paths to the ld.so cache as Prof Ripley had suggested. I get the
same results when running configure. 

So after that I decided to try and replace libRblas.so with a link to
libacml_mp.so. I ran a regular configure command followed by a make, then
added the link.  I now have this in my R lib folder... 
lrwxrwxrwx  1 root root   46 2010-08-25 09:20 libRblas.so ->
/opt/acml4.4.0/gfortran64_mp/lib/libacml_mp.so*

Is there any way I can verify that it is using this libacml_mp library now?
I ran a test script and R still only shows 100% cpu use, as if it's not
using multiple processors/cores. Is there a specific sample script I could
run that should use more than 100% so I can verify whether this is working
or not? Or maybe a command that will tell me which BLAS R is using? Thanks
in advance.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Trying-to-configure-R-to-use-acml-mp-tp2338257p2338257.html
Sent from the R devel mailing list archive at Nabble.com.

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


Re: [Rd] Trying to configure R to use acml_mp

2010-08-25 Thread szembek

Ok, I have verified that ACML appears to be working because when I run 

set.seed (1)
m <- 1
n <-  5000
A <- matrix (runif (m*n),m,n)
system.time (B <- crossprod(A))

It multi threads properly. My initial test script doesn't seem to utilize
multiple cores, I am going to paste it below if anyone has any insight as to
why R can't multithread this particular operation. It seems it might just be
a code optimization problem on our end, at least I know that R is configured
to use multiple cores when it can now.

Y <- rnorm(1e5)
X <- matrix(as.factor(rep(1:1e2, 5e3)), 1e5, 10)
system.time(fit <- lm(Y~X[,1] + X[,2] + X[,3] + X[,4] + X[,5]))

Thanks
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Trying-to-configure-R-to-use-acml-mp-tp2338257p2338482.html
Sent from the R devel mailing list archive at Nabble.com.

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


[Rd] No [[<-.factor()

2010-08-25 Thread William Dunlap
Should there be a [[<-.factor() that either throws
an error or acts like [<-.factor() to avoid making
an illegal object of class factor?

  > z <- factor(c("Two","Two","Three"), levels=c("One","Two","Three"))
  > z
  [1] Two   Two   Three
  Levels: One Two Three
  > str(z)
   Factor w/ 3 levels "One","Two","Three": 2 2 3
  > z[[2]] <- "One"
  > str(z) # the .Data part is now character
   Factor w/ 3 levels "One","Two","Three": 2 One 3
  > z
  [1]   
  Levels: One Two Three
  > z[2] <- "One"
  Error in class(x) <- cx : adding class "factor" to an invalid object

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

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


[Rd] Speeding up transpose

2010-08-25 Thread Radford Neal
I've looked at how to speed up the transpose function in R 
(ie, t(X)).

The existing code does the work with loops like the following:

for (i = 0; i < len; i++)
REAL(r)[i] = REAL(a)[(i / ncol) + (i % ncol) * nrow];

It seems a bit optimistic to expect a compiler to produce good code 
from this.  I've re-written these loops as follows:

for (i = 0, j = 0; i=len) j -= (len-1);
REAL(r)[i] = REAL(a)[j];
}

The resulting improvement is sometimes dramatic.  Here's a test 
program:

M <- matrix(seq(0,1,12000),200,60)

print(system.time({for (i in 1:1) S <- t(M)}))
print(system.time({for (i in 1:1) R <- t(S)}))

v <- seq(0,2,12000)

print(system.time({for (i in 1:10) u <- t(v)}))
print(system.time({for (i in 1:10) w <- t(u)}))

Here are the times on an Intel Linux system:

R version 2.11.1:Modified version:

 user  system elapsed  user  system elapsed 
1.190   0.040   1.232 0.610   0.010   0.619 
 user  system elapsed  user  system elapsed 
1.200   0.020   1.226 0.610   0.000   0.616 
 user  system elapsed  user  system elapsed 
0.800   0.010   0.813 0.750   0.000   0.752 
 user  system elapsed  user  system elapsed 
0.910   0.010   0.921 0.860   0.000   0.864 

Here are the times on a SPARC Solaris system:

R version 2.11.1:Modified version:

 user  system elapsed  user  system elapsed 
   18.643   0.041  18.685 2.994   0.039   3.033
 user  system elapsed  user  system elapsed 
   18.574   0.041  18.616 3.123   0.039   3.163
 user  system elapsed  user  system elapsed 
3.803   0.271   4.075 3.868   0.296   4.163
 user  system elapsed  user  system elapsed 
4.184   0.273   4.457 4.238   0.302   4.540

So with the modification, transpose for a 60x200 or 200x60 matrix is
about a factor of two faster on the Intel system, and a factor of six
faster on the SPARC system.  There is little or no gain from the
modification when transposing a row or column vector, however.  (I
think it must be that on these machines multiplies and divides do not
take constant time, but are faster when, for instance, dividing by 1.)

I've appended below the new version of the modified part of the
do_transpose function in src/main/array.c.

Radford Neal

--

PROTECT(r = allocVector(TYPEOF(a), len));
switch (TYPEOF(a)) {
case LGLSXP:
case INTSXP:
for (i = 0, j = 0; i=len) j -= (len-1);
INTEGER(r)[i] = INTEGER(a)[j];
}
case REALSXP:
for (i = 0, j = 0; i=len) j -= (len-1);
REAL(r)[i] = REAL(a)[j];
}
break;
case CPLXSXP:
for (i = 0, j = 0; i=len) j -= (len-1);
COMPLEX(r)[i] = COMPLEX(a)[j];
}
break;
case STRSXP:
for (i = 0, j = 0; i=len) j -= (len-1);
SET_STRING_ELT(r, i, STRING_ELT(a,j));
}
break;
case VECSXP:
for (i = 0, j = 0; i=len) j -= (len-1);
SET_VECTOR_ELT(r, i, VECTOR_ELT(a,j));
}
break;
case RAWSXP:
for (i = 0, j = 0; i=len) j -= (len-1);
RAW(r)[i] = RAW(a)[j];
}
break;
default:
UNPROTECT(1);
goto not_matrix;
}

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