English 中文(简体)
哪一种最佳做法将违约价值设定为参考数据框架的论点?
原标题:What s the best practice setting a default value to a const reference DataFrame argument in Rcpp?
  • 时间:2023-10-11 02:38:51
  •  标签:
  • r
  • rcpp

在Rcpp功能foo中,data可能是一个大的数据框架,因此,我也将其作为一个参考。 现在,我想把它的缺省价值确定为空数据框架,以便用户能够简单地在R中打电话foo(<>/code>,但不得打foo(data.frame()

我试图这样做:

#include <Rcpp.h>
using namespace Rcpp;

//[[Rcpp::export]]
DataFrame foo(const DataFrame &data = DataFrame())
{
    //Do something
}

但看来,<代码>DataFrame(>)被视为违约值。 我试图推翻这一职能:

#include <Rcpp.h>
using namespace Rcpp;

//[[Rcpp::export]]
DataFrame foo(const DataFrame &data)
{
    //Do something
}

//[[Rcpp::export]]
DataFrame foo()
{
    DataFrame data = DataFrame::create();
    return foo(data);
}

但是,Rcpp告诉我有相互矛盾的声明。 作者:

#include <Rcpp.h>
using namespace Rcpp;

//[[Rcpp::export]]
DataFrame foo(Nullable<DataFrame> data_ = R_NilValue)
{
    DataFrame data;
    if (data_.isNotNull())
    {
        data = DataFrame(data_);
    }
    else
    {
        data = DataFrame::create();
    }
    // Do something
}

它目前运作良好,但我想:

  1. Is this the best (simplest) way to do this?
  2. In this case, will data passed as copy or refernce?

还是任何其他解决办法?

问题回答

“如果做不到工作,就会尝试一些简单的工作”。

数据框架是一个大类,但是它没有本地的SEXP目标,因此难以建立Rcpp基础设施。 数据框架实际上只是一份(相当长的)病媒清单。 因此,在返回时,我主要在最后一步建立数据框架,将不同栏目(混为一谈)作为主要目标处理。 接着:从一栏开始,就这些病媒开展工作。

我试图在RcppExamples包和Rcpp美术馆收集少量文件。 但这是。

(Lastly, “how do it come in ?” that is general not a worry as Rcpp always <>m>always crosss R through .Call( which take (zero or more) SEXP and Return a SEXP. 因此,你总是处在pointers的边缘,不能完全排除正在复制的物体。

If you have ideas (and better, code) to make things better we are likely going to be all ears.





相关问题
How to plot fitted model over observed time series

This is a really really simple question to which I seem to be entirely unable to get a solution. I would like to do a scatter plot of an observed time series in R, and over this I want to plot the ...

REvolution for R

since the latest Ubuntu release (karmic koala), I noticed that the internal R package advertises on start-up the REvolution package. It seems to be a library collection for high-performance matrix ...

R - capturing elements of R output into text files

I am trying to run an analysis by invoking R through the command line as follows: R --no-save < SampleProgram.R > SampleProgram.opt For example, consider the simple R program below: mydata =...

R statistical package: wrapping GOFrame objects

I m trying to generate GOFrame objects to generate a gene ontology mapping in R for unsupported organisms (see http://www.bioconductor.org/packages/release/bioc/vignettes/GOstats/inst/doc/...

Changing the order of dodged bars in ggplot2 barplot

I have a dataframe df.all and I m plotting it in a bar plot with ggplot2 using the code below. I d like to make it so that the order of the dodged bars is flipped. That is, so that the bars labeled "...

Strange error when using sparse matrices and glmnet

I m getting a weird error when training a glmnet regression. invalid class "dgCMatrix" object: length(Dimnames[[2]]) must match Dim[2] It only happens occasionally, and perhaps only under larger ...

Generating non-duplicate combination pairs in R

Sorry for the non-descriptive title but I don t know whether there s a word for what I m trying to achieve. Let s assume that I have a list of names of different classes like c( 1 , 2 , 3 , 4 ) ...

Per panel smoothing in ggplot2

I m plotting a group of curves, using facet in ggplot2. I d like to have a smoother applied to plots where there are enough points to smooth, but not on plots with very few points. In particular I d ...

热门标签