我想构建一个包,但我使用RcppArmadillo编写了其中的一部分,现在我正在承受后果。我正在使用roxygen2和devtools来帮助我处理DESCRIPTION和NAMESPACE。我正在用R/Ubuntu进行编码。在描述中,我包括两行来装载包裹:
取决于:R(>=3.4.4(、MASS链接到:Rcpp,Rcpp Armadillo
在文件夹/src中,我写了一个脚本名loss_function.cpp,里面有:
> // [[Rcpp::depends(RcppArmadillo)]]
>
> #include <RcppArmadillo.h>
>
> using namespace Rcpp;
>
> //' Check function.
> //'
> //' @param x vector
> //' @param tau percentile
> //' @return y new vector
> // [[Rcpp::export(rho_koenker)]]
> arma::vec rho_koenker(arma::vec x, double tau){
> int n = x.n_elem;
> arma::vec y(n);
> for(int i = 0; i < n; ++i){
> if(x(i)<0){
> y(i) = x(i)*(tau-1);
> } else {
> y(i) = x(i)*tau;
> }
> }
> return(y);
> }
>
> //' Quantile regression loss function
> //'
> //' @param beta parameter
> //' @param x matrix
> //' @param y vector
> //' @param tau percentile
> //' @param N total number of observations
> //' @param d beta's length
> //' @return eta numeric
> // [[Rcpp::export(loss_qr)]]
> double loss_qr(arma::vec beta, arma::mat x, arma::vec y, double tau, int N, int d){
> double eta = 0;
> arma::vec res(N);
> arma::vec rho(N);
> res = y - (x * beta);
> rho = rho_koenker(res,tau);
> eta = accu(rho);
> return(eta);
> }
当我检查包(build->检查包(时,出现错误消息:
Error in .Call("_pqfe_loss_qr", PACKAGE = "pqfe", beta, x, y, tau, N, :
"_pqfe_loss_qr" not available for .Call() for package "pqfe"
Calls: qr ... optim_qr -> <Anonymous> -> <Anonymous> -> fn -> .Call
Execution halted
Warning message:
Can't find generic `sew` in package knitr to register S3 method.
This message is only shown to developers using devtools.
Do you need to update knitr to the latest version?
正如上面的注释所暗示的,不清楚RcppArmadillo
的错误所在。所以我
-
调用
RcppArmadillo.package.skeleton()
(通过来自littler
的助手命令kitten.r
,依赖于pkgKitten
,但这些都是详细信息( -
基于您的在
src/loss_function.cpp
中添加 -
为doxygen/roxygen添加了一个缺失的
@export
标签,以使R文档也创建 -
称为
Rcpp::compileAttributes()
(通过来自"littler"的助手compAttr.r
(以生成/更新内部粘合代码 -
被称为
roxygenize()
(通过来自littler
的助手roxy.r
(以创建的帮助文件 -
称为
R CMD build
(直接或经由来自littler
的助手build.r
( -
运行
R CMD check
(直接或通过来自littler
的助手rcc.r
(
一切正常:
edd@rob:~/git/stackoverflow/73405262(master)$ R CMD build soDemo
* checking for file ‘soDemo/DESCRIPTION’ ... OK
* preparing ‘soDemo’:
* checking DESCRIPTION meta-information ... OK
* cleaning src
* installing the package to process help pages
* saving partial Rd database
* cleaning src
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* building ‘soDemo_1.0.tar.gz’
edd@rob:~/git/stackoverflow/73405262(master)$
并且检查得也很好
edd@rob:~/git/stackoverflow/73405262(master)$ R CMD check soDemo_1.0.tar.gz
* using log directory ‘/home/edd/git/stackoverflow/73405262/soDemo.Rcheck’
* using R version 4.2.1 (2022-06-23)
* using platform: x86_64-pc-linux-gnu (64-bit)
* using session charset: UTF-8
* checking for file ‘soDemo/DESCRIPTION’ ... OK
* checking extension type ... Package
* this is package ‘soDemo’ version ‘1.0’
* package encoding: UTF-8
* checking package namespace information ... OK
* checking package dependencies ... OK
* checking if this is a source package ... OK
* checking if there is a namespace ... OK
* checking for executable files ... OK
* checking for hidden files and directories ... OK
* checking for portable file names ... OK
* checking for sufficient/correct file permissions ... OK
* checking whether package ‘soDemo’ can be installed ... OK
* checking installed package size ... OK
* checking package directory ... OK
* checking DESCRIPTION meta-information ... OK
* checking top-level files ... OK
* checking for left-over files ... OK
* checking index information ... OK
* checking package subdirectories ... OK
* checking R files for non-ASCII characters ... OK
* checking R files for syntax errors ... OK
* checking whether the package can be loaded ... OK
* checking whether the package can be loaded with stated dependencies ... OK
* checking whether the package can be unloaded cleanly ... OK
* checking whether the namespace can be loaded with stated dependencies ... OK
* checking whether the namespace can be unloaded cleanly ... OK
* checking loading without being on the library search path ... OK
* checking dependencies in R code ... OK
* checking S3 generic/method consistency ... OK
* checking replacement functions ... OK
* checking foreign function calls ... OK
* checking R code for possible problems ... OK
* checking Rd files ... OK
* checking Rd metadata ... OK
* checking Rd cross-references ... OK
* checking for missing documentation entries ... OK
* checking for code/documentation mismatches ... OK
* checking Rd usage sections ... OK
* checking Rd contents ... OK
* checking for unstated dependencies in examples ... OK
* checking line endings in C/C++/Fortran sources/headers ... OK
* checking line endings in Makefiles ... OK
* checking compilation flags in Makevars ... OK
* checking for GNU extensions in Makefiles ... OK
* checking for portable use of $(BLAS_LIBS) and $(LAPACK_LIBS) ... OK
* checking use of PKG_*FLAGS in Makefiles ... OK
* checking compilation flags used ... OK
* checking compiled code ... OK
* checking examples ... OK
* checking for unstated dependencies in ‘tests’ ... OK
* checking tests ...
Running ‘tinytest.R’
OK
* checking PDF version of manual ... OK
* DONE
Status: OK
edd@rob:~/git/stackoverflow/73405262(master)$
如果你想从这里拿走,我会把防水布放在这里。