2017-08-10 7 views
0

Rcpp初心者の質問には依存関係を追加します。は私のRcppパッケージ

質問。私は.cppファイルに他のいくつかのRパッケージを使用しており、ユーザーが自分のパッケージをインストールするときにこれらのパッケージを自動的にインストールしてインポートしたいと考えています。

* installing to library 'C:/Program Files/R/R-3.4.1/library' 
* installing *source* package 'pkgname' ... 
make: Nothing to be done for `all`. 
** libs 
installing to C:/Program Files/R/R-3.4.1/library/pkgname/libs/i386 
** R 
** preparing package for lazy loading 
Error in library(gtools) : there is no package called 'gtools' 
Error : unable to load R code in package 'pkgname' 
ERROR: lazy loading failed for package 'pkgname' 
* removing 'C:/Program Files/R/R-3.4.1/library/pkgname' 

Exited with status 1. 

私はDESCRIPTIONファイルに依存元パッケージ名を追加しようとしました:私は私のファイル内のRパッケージ「gtools」を使用した場合、私はエラーをしたくありません。すなわち

Imports: Rcpp (>= 0.12.12),gtools 
LinkingTo: Rcpp, gtools 

しかし、それはエラー、次の私を与える:私は同様の質問を検索し、ある場合は、私に教えてくださいません

ERROR: dependency 'gtools' is not available for package 'pkgname' 

答えて

2

まず、あなたはおそらくgtoolsがシステムにをインストールされていることを確認する必要があります。私は次のエラーのためにこれを言う:これにより

Error in library(gtools) : there is no package called 'gtools'

は、あなたがに実行している主な問題はDESCRIPTIONファイル内LinkingTo:Imports:フィールド間の不確実性がある言われています。これは、Section 1.1.3: Package DependenciesWriting R Extensionsでカバーされています。

具体的には、我々は持っている:

The ‘Imports’ field lists packages whose namespaces are imported from (as specified in the NAMESPACE file) but which do not need to be attached. Namespaces accessed by the ‘::’ and ‘:::’ operators must be listed here, or in ‘Suggests’ or ‘Enhances’ (see below). Ideally this field will include all the standard packages that are used, and it is important to include S4-using packages (as their class definitions can change and the DESCRIPTION file is used to decide which packages to re-install when this happens). Packages declared in the ‘Depends’ field should not also be in the ‘Imports’ field. Version requirements can be specified and are checked when the namespace is loaded (since R >= 3.0.0).

そしてLinkingToフィールド:だから

A package that wishes to make use of header files in other packages needs to declare them as a comma-separated list in the field ‘LinkingTo’ in the DESCRIPTION file. For example

LinkingTo: link1, link2 

The ‘LinkingTo’ field can have a version requirement which is checked at installation.

Specifying a package in ‘LinkingTo’ suffices if these are C++ headers containing source code or static linking is done at installation: the packages do not need to be (and usually should not be) listed in the ‘Depends’ or ‘Imports’ fields. This includes CRAN package BH and almost all users of RcppArmadillo and RcppEigen .

For another use of ‘LinkingTo’ see Linking to native routines in other packages .

Imports:をインポートしたいR機能を含むパッケージを指定するためのものです。特に、指定されたパッケージまたはパッケージ全体の関数は、NAMESPACEファイルで指定する必要があります。 Rcppを使用するパッケージの場合、作成者がC++からルーチンをエクスポートした場合、通常Rの関数が利用可能になると期待できます。

LinkingTo:については、これはもう少し具体的です。投稿者がC++ APIをヘッダファイル経由で利用できるようにするには、native methodsWriting R Extensionsに記載されているように明示的に宣言する必要があります。一般に、このように進行するパッケージは「ヘッダーのみ」です。これらのパッケージはヘッダ定義をinst/includeの下に置きます。

|- pkgname 
    |- inst/ 
     |- include/ 
     |- pkgname.h 
    |- R/ 
    |- man/ 
    |- DESCRIPTION 
    |- NAMESPACE 

しかし、別の傾向として、「非ヘッダ」パッケージを使用することができます。これは、共有オブジェクトと動的ライブラリを理解する必要があるため、トピックが少し複雑になります。著者は、C++ API利用できないメイクをした場合はCRANはWriting R Extensions

Section 5.8: Linking to other packagesどのように「リンク」のパッケージにの概要を説明し、その後、オプションがあります:

  1. が掲載authorAPIを呼び出すか、C++ APIへのアクセスを可能にするパッチを提出してください。
  2. Call an R function from C++。これにより、コードを書くことによるパフォーマンスの向上は、 C++になります。
  3. 知的財産を尊重しながら、実装を著者のパッケージからコピーします。
  4. ライセンスの問題を避けるために、ゼロから目的の機能を実装します。

残念ながら、これはgtoolsの場合です。作者はdo not provide a means to "link" to the C++ version of package's codeです。

関連する問題