[Rcpp-commits] r2582 - in pkg: . patches patches/R patches/man patches/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Nov 29 11:54:09 CET 2010


Author: romain
Date: 2010-11-29 11:54:09 +0100 (Mon, 29 Nov 2010)
New Revision: 2582

Added:
   pkg/patches/
   pkg/patches/DESCRIPTION
   pkg/patches/NAMESPACE
   pkg/patches/R/
   pkg/patches/R/zzz.R
   pkg/patches/man/
   pkg/patches/man/patches-package.Rd
   pkg/patches/src/
   pkg/patches/src/Makevars
   pkg/patches/src/Makevars.win
   pkg/patches/src/Module.cpp
   pkg/patches/src/patches.h
   pkg/patches/src/sequence.cpp
Log:
new package: patches

Added: pkg/patches/DESCRIPTION
===================================================================
--- pkg/patches/DESCRIPTION	                        (rev 0)
+++ pkg/patches/DESCRIPTION	2010-11-29 10:54:09 UTC (rev 2582)
@@ -0,0 +1,12 @@
+Package: patches
+Type: Package
+Title: Collection of hot pacthes for R
+Version: 0.0
+Date: 2010-11-29
+Author: Romain Francois
+Maintainer: Romain Francois <romain at r-enthusiasts.com>
+Description: Collection of hot pacthes for R
+License: GPL (>= 2.0)
+LazyLoad: yes
+Depends: R (>= 2.12.0), Rcpp (>= 0.8.9)
+LinkingTo: Rcpp

Added: pkg/patches/NAMESPACE
===================================================================
--- pkg/patches/NAMESPACE	                        (rev 0)
+++ pkg/patches/NAMESPACE	2010-11-29 10:54:09 UTC (rev 2582)
@@ -0,0 +1,3 @@
+useDynLib(patches)
+import(Rcpp)
+

Added: pkg/patches/R/zzz.R
===================================================================
--- pkg/patches/R/zzz.R	                        (rev 0)
+++ pkg/patches/R/zzz.R	2010-11-29 10:54:09 UTC (rev 2582)
@@ -0,0 +1,15 @@
+
+hijack <- function(name, value, namespace = "base" ){
+	namespace <- asNamespace( namespace )
+	unlockBinding( name, namespace )
+	assign( name, value, envir = namespace )
+	lockBinding(name, namespace )
+}
+
+
+.onLoad <- function(libname, pkgname){
+	m <- Module( "patches" )
+	hijack( "sequence", m$sequence )
+}    
+
+

Added: pkg/patches/man/patches-package.Rd
===================================================================
--- pkg/patches/man/patches-package.Rd	                        (rev 0)
+++ pkg/patches/man/patches-package.Rd	2010-11-29 10:54:09 UTC (rev 2582)
@@ -0,0 +1,30 @@
+\name{patches-package}
+\alias{patches-package}
+\alias{patches}
+\docType{package}
+\title{
+Collection of hot pacthes for R
+}
+\description{
+Collection of hot pacthes for R
+}
+\details{
+\tabular{ll}{
+Package: \tab patches\cr
+Type: \tab Package\cr
+Version: \tab 0.0\cr
+Date: \tab 2010-11-29\cr
+License: \tab GPL (>=2)\cr
+LazyLoad: \tab yes\cr
+}
+
+A faster version of \link[base]{sequence} is installed
+in the base namespace when patches loads. 
+
+}
+\author{
+Romain Francois
+
+Maintainer: Romain Francois <romain at r-enthusiasts.com>
+}
+\keyword{ package }

Added: pkg/patches/src/Makevars
===================================================================
--- pkg/patches/src/Makevars	                        (rev 0)
+++ pkg/patches/src/Makevars	2010-11-29 10:54:09 UTC (rev 2582)
@@ -0,0 +1,27 @@
+## Use the R_HOME indirection to support installations of multiple R version
+PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"`
+
+## As an alternative, one can also add this code in a file 'configure'
+##
+##    PKG_LIBS=`${R_HOME}/bin/Rscript -e "Rcpp:::LdFlags()"`
+## 
+##    sed -e "s|@PKG_LIBS@|${PKG_LIBS}|" \
+##        src/Makevars.in > src/Makevars
+## 
+## which together with the following file 'src/Makevars.in'
+##
+##    PKG_LIBS = @PKG_LIBS@
+##
+## can be used to create src/Makevars dynamically. This scheme is more
+## powerful and can be expanded to also check for and link with other
+## libraries.  It should be complemented by a file 'cleanup'
+##
+##    rm src/Makevars
+##
+## which removes the autogenerated file src/Makevars. 
+##
+## Of course, autoconf can also be used to write configure files. This is
+## done by a number of packages, but recommended only for more advanced users
+## comfortable with autoconf and its related tools.
+
+

Added: pkg/patches/src/Makevars.win
===================================================================
--- pkg/patches/src/Makevars.win	                        (rev 0)
+++ pkg/patches/src/Makevars.win	2010-11-29 10:54:09 UTC (rev 2582)
@@ -0,0 +1,4 @@
+
+## Use the R_HOME indirection to support installations of multiple R version
+PKG_LIBS = $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "Rcpp:::LdFlags()")
+

Added: pkg/patches/src/Module.cpp
===================================================================
--- pkg/patches/src/Module.cpp	                        (rev 0)
+++ pkg/patches/src/Module.cpp	2010-11-29 10:54:09 UTC (rev 2582)
@@ -0,0 +1,8 @@
+#include "patches.h"
+
+using namespace Rcpp ;
+
+RCPP_MODULE(patches){
+    function( "sequence", &sequence, List::create( _["nvec"] ) ) ;   
+}
+

Added: pkg/patches/src/patches.h
===================================================================
--- pkg/patches/src/patches.h	                        (rev 0)
+++ pkg/patches/src/patches.h	2010-11-29 10:54:09 UTC (rev 2582)
@@ -0,0 +1,8 @@
+#ifndef _patches_RCPP_HELLO_WORLD_H
+#define _patches_RCPP_HELLO_WORLD_H
+
+#include <Rcpp.h>
+
+Rcpp::IntegerVector sequence(Rcpp::IntegerVector) ;
+
+#endif

Added: pkg/patches/src/sequence.cpp
===================================================================
--- pkg/patches/src/sequence.cpp	                        (rev 0)
+++ pkg/patches/src/sequence.cpp	2010-11-29 10:54:09 UTC (rev 2582)
@@ -0,0 +1,33 @@
+#include "patches.h"
+
+using namespace Rcpp ;
+
+IntegerVector sequence(IntegerVector nvec){
+BEGIN_RCPP
+    
+    IntegerVector x(nvec ) ;
+    R_len_t n = x.size(), s = 0 ;
+    IntegerVector::iterator px = x.begin() ;
+    int x_i ;
+    
+    /* error checking */
+    for( int i=0; i<n; i++){
+        x_i = px[i] ;
+        if( x_i == NA_INTEGER || x_i <= 0 ) 
+            throw std::range_error( "argument must be coercible to non-negative integer" ) ;
+        s += x_i ;
+    }
+        
+    IntegerVector out( s ) ;
+    int end ;
+    for( int i=0, start=0; i<n; i++){
+        x_i = x[i] ;
+        end = start + x_i - 1;
+        out[ Range( start, end ) ] = seq_len( x_i ) ;
+        start = end + 1;
+    } 
+    return out ;
+    
+END_RCPP
+}                  
+



More information about the Rcpp-commits mailing list