title: Rcpp (function with default null parameter): Not compatible with requested type: [type=NULL; target=double]
body: <p>My Rcpp code is shown here, I have used sourceCpp to compile the cpp file. No error is reported, just some warnings there. When I tried to implement the function <strong>softImpute</strong> using <strong>softImpute(m1, NULL, mr1, mr2, 0, -1)</strong>, the reported error is <strong>Not compatible with requested type: [type=NULL; target=double]</strong>.</p>
  <p>Note: <strong>m1</strong> is a numeric matrix, <strong>mr1</strong> and <strong>mr2</strong> are two logical matrix. For example, we can generate m1, mr1, mr2 as below:</p>
  <pre><code>m1 &lt;- matrix(rnorm(30),5,6)
  mr1 &lt;- matrix(runif(30) &gt; 0.5,5,6)
  mr2 &lt;- !mr1
  </code></pre>
  <p>Do you have any idea to address this error? Thank you in advance!</p>
  <p><strong>Rcpp code:</strong></p>
  <pre><code>#include &lt;RcppArmadillo.h&gt;
  
  // [[Rcpp::depends(RcppArmadillo)]]
  // [[Rcpp::export]]
  Rcpp::List dcSVD(arma::mat X) {
    arma::mat u, v;
    arma::vec d;
    arma::svd(u, d, v, X, &quot;dc&quot;);
    return Rcpp::List::create(Rcpp::Named(&quot;u&quot;) = u,
                              Rcpp::Named(&quot;d&quot;) = d,
                              Rcpp::Named(&quot;v&quot;) = v);
  }
  
  // [[Rcpp::depends(RcppArmadillo)]]
  // [[Rcpp::export]] 
  Rcpp::List svd_st(arma::mat X, double lambda){
    
    Rcpp::List mysvd = dcSVD(X);
    arma::mat U = mysvd[&quot;u&quot;];
    arma::mat V = mysvd[&quot;v&quot;];
    arma::mat VT = V.t();
    arma::vec d = mysvd[&quot;d&quot;];
    arma::mat D = arma::diagmat(d);
    arma::uvec index_list = arma::find(d &gt;= lambda);
    arma::vec w;
    arma::mat W;
    arma::mat L;
    if(index_list.n_elem &gt; 1){
      w = d.elem(index_list) - lambda;
      W = arma::diagmat(w);
      arma::mat U1 = U.cols(index_list);
      arma::mat VT1 = VT.rows(index_list);
      L = U1 * W * VT1; 
    }else if(index_list.n_elem == 1){
      w = d.elem(index_list) - lambda;
      W = arma::diagmat(w);
      L = U.cols(index_list) * W * VT.rows(index_list);
    }else if(index_list.n_elem == 0){
      W = arma::zeros(1,1);
      L = arma::zeros(X.n_rows, X.n_cols);
    }
    return Rcpp::List::create(Rcpp::Named(&quot;L&quot;) = L, Rcpp::Named(&quot;W&quot;) = W); 
  }
  
  // [[Rcpp::depends(RcppArmadillo)]]
  // [[Rcpp::export]]
  Rcpp::List soft(arma::mat X, Rcpp::Nullable&lt;Rcpp::NumericMatrix&gt; Z_ = R_NilValue, Rcpp::Nullable&lt;Rcpp::LogicalMatrix&gt; Ome_ = R_NilValue, 
                        Rcpp::Nullable&lt;Rcpp::LogicalMatrix&gt; Ome1_ = R_NilValue, Rcpp::Nullable&lt;Rcpp::LogicalMatrix&gt; Ome2_ = R_NilValue, 
                        Rcpp::Nullable&lt;Rcpp::NumericVector&gt; alpha0_ = R_NilValue, Rcpp::Nullable&lt;Rcpp::NumericVector&gt; maxRank_ = R_NilValue){
    
    Rcpp::NumericMatrix ZH = R_NilValue;
    double alpha = 0; 
    int maxRank = -1; 
    arma::mat Z;
    if (Ome_.isNotNull() &amp;&amp; Ome1_.isNotNull() &amp;&amp; Ome2_.isNotNull()){
      Rcpp::LogicalMatrix Ome(Ome_);
      arma::umat Omega = Rcpp::as&lt;arma::umat&gt;(Ome);
      Rcpp::LogicalMatrix Ome1(Ome1_);
      arma::umat Omega1 = Rcpp::as&lt;arma::umat&gt;(Ome1);
      Rcpp::LogicalMatrix Ome2(Ome2_);
      arma::umat Omega2 = Rcpp::as&lt;arma::umat&gt;(Ome2);
      arma::mat X_0 = X % Omega;
      if (!Z_.isNotNull()){
        Rcpp::NumericMatrix ZH = Rcpp::wrap(X_0);     
      }else{  
        Rcpp::NumericMatrix ZH = Rcpp::as&lt;Rcpp::NumericMatrix&gt;(Z_);
      }
      if (!alpha0_.isNotNull()){
        Rcpp::List my_svd = dcSVD(X_0);
        arma::vec d = my_svd[&quot;d&quot;];
        double alpha = arma::as_scalar(d(1));  
      }else{
        Rcpp::NumericVector aa(alpha0_);
        double alpha = arma::as_scalar(aa(0)); 
      }
      if (!maxRank_.isNotNull()){
        int maxRank = -1;  
      }else{
        Rcpp::NumericVector bb(maxRank_);
        int maxRank = arma::as_scalar(bb(0));  
      }    
      Z = Rcpp::as&lt;arma::mat&gt;(ZH);
    }
    return Rcpp::List::create(Rcpp::Named(&quot;Z&quot;) = Z, 
                              Rcpp::Named(&quot;alpha&quot;) = alpha, 
                              Rcpp::Named(&quot;maxRank&quot;) = maxRank);
  }  
  </code></pre>