[R-pkg-devel] R package with RcppArmadillo

Maity, Arnab K akumar at stat.tamu.edu
Thu Jun 8 18:53:09 CEST 2017


I am unable to provide a whole bunch of reproducible example at this point of time and I apologize for that. But I am very much hoping someone can throw some light by seeing the following error message.


> document("afths")
Updating afths documentation
Loading afths
Re-compiling afths
"C:/Users/akumar/DOCUME~1/R/R-33~1.2/bin/x64/R" --no-site-file --no-environ --no-save --no-restore --quiet CMD INSTALL  \
  "C:\Users\akumar\Documents\ARNAB TAMU\Research\Survival Regression\Codes\R\Package v1\afths"  \
  --library="C:\Users\akumar\AppData\Local\Temp\RtmpKOAiCH\devtools_install_c9c6ac540c2" --no-R --no-data --no-help  \
  --no-demo --no-inst --no-docs --no-exec --no-multiarch --no-test-load --preclean

* installing *source* package 'afths' ...
** libs
Warning: running command 'make -f "Makevars.win" -f "C:/Users/akumar/DOCUME~1/R/R-33~1.2/etc/x64/Makeconf" -f "C:/Users/akumar/DOCUME~1/R/R-33~1.2/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="afths.dll" WIN=64 TCLBIN=64 OBJECTS="RcppExports.o rBeta1.o rBeta2.o rbetak.o" shlib-clean' had status 127
Warning: running command 'make -f "Makevars.win" -f "C:/Users/akumar/DOCUME~1/R/R-33~1.2/etc/x64/Makeconf" -f "C:/Users/akumar/DOCUME~1/R/R-33~1.2/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="afths.dll" WIN=64 TCLBIN=64 OBJECTS="RcppExports.o rBeta1.o rBeta2.o rbetak.o"' had status 127
ERROR: compilation failed for package 'afths'
* removing 'C:/Users/akumar/AppData/Local/Temp/RtmpKOAiCH/devtools_install_c9c6ac540c2/afths'
Error: Command failed (1)

Some background information: I am trying to develop a package "afths" with some R and C++ functions. I developed the package skeleton using RcppArmadillo.package.skeleton(). Then I created a file namely "afths.R" in the R folder which contains

#' @useDynLib YourPackageName
#' @importFrom Rcpp evalCpp
#' @exportPattern "^[[:alpha:]]+"
NULL?

Then I try to produce manuals in man folder using devtools::document("afths").

I am providing the chunk of codes in rBeta1.cpp as an example, if it helps:

// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-

// we only include RcppArmadillo.h which pulls Rcpp.h in for us
#include "RcppArmadillo.h"

using namespace Rcpp;
using namespace arma;


// via the depends attribute we tell Rcpp to create hooks for
// RcppArmadillo so that the build process will know what to do
//
// [[Rcpp::depends(RcppArmadillo)]]

?//
// via the exports attribute we tell Rcpp to make this function
// available from R
//
// [[Rcpp::export]]
arma::mat rcpparma_hello_world() {
    arma::mat m1 = arma::eye<arma::mat>(3, 3);
    arma::mat m2 = arma::eye<arma::mat>(3, 3);

    return m1 + 3 * (m1 + m2);
}


// another simple example: outer product of a vector,
// returning a matrix
//
// [[Rcpp::export]]
Rcpp::List rBeta1( const arma::mat& X,
                   const arma::colvec& y,
                   const arma::colvec& lambda, //lambda
                   const double tau, //tau
                   const double sigma_sq

){
  //declarations
  const unsigned int n = X.n_rows; //number of rows of X
  const unsigned int p = X.n_cols; //number of columns of X
  arma::mat U = zeros(p,n);
  arma::mat I = eye(n,n);
  arma::colvec lambda_star = zeros(p); //lambda_star
  arma::colvec u = zeros(p);
  arma::colvec v = zeros(n);
  arma::colvec v_star = zeros(n); //v_star
  arma::colvec Beta = zeros(p); // Beta



  lambda_star = tau * lambda;
  U = diagmat(square(lambda_star))*trans(X);

  // step 1 //
  u = randn(p)%lambda_star;
  v = X*u + randn(n);

  // step 2 //
  v_star = solve((X*U + I) , (y/sqrt(sigma_sq) - v));
  Beta = sqrt(sigma_sq)* (u + U*v_star);

  return Rcpp::List::create( Named("Beta") = Beta);
}








Arnab Kumar Maity
Department of Statistics
Texas A&M University
3143 TAMU, Room 401A
College Station, TX 77843
akumar at stat.tamu.edu<mailto:arnabkrmaity at stat.tamu.edu>
arnabkrmaity at tamu.edu
+1 779 777 3428<tel:%2B1%20779%20777%203428>

	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list