I try to create a R package (using Rcpp). Everything works fine. But now I wrote a c++ function, which I want to call in an other c++ file. So in /src there is:
- function1 = linearInterpolation.cpp
- function2 = getSlope.cpp
Let's take function1, which just do a linear interpolation between two points at a specific position.
#include <Rcpp.h>
using namespace Rcpp;
//' @name linearInterpolation
//' @title linearInterpolation
//' @description Twodimensional linearinterpolation for a specific point
//' @param xCoordinates Two x coordinates
//' @param yCoordinates Coresponding two y coordinates
//' @param atPosition The Point to which the interpolation shall be done
//' @return Returns the linear interpolated y-value for the specific point
//' @examples
//' linearInterpolation(c(1,2),c(1,4),3)
//'
//' @export
// [[Rcpp::export]]
double linearInterpolation(NumericVector xCoordinates, NumericVector yCoordinates, double atPosition) {
// start + delta y / delta x_1 * delta x_2
return yCoordinates[1] + getSlope(xCoordinates, yCoordinates) * (atPosition - xCoordinates[1]);
}
and the slope is calculated in a different function (file).
#include <Rcpp.h>
using namespace Rcpp;
//' @name getSlope
//' @title getSlope
//' @description Calculates the slopes between two points in 2Dimensions
//' @param xCoordinates Two x coordinates
//' @param yCoordinates Coresponding two y coordinates
//' @return Returns the slope
//' @examples
//' getSlope(c(1,2),c(1,4),3)
//'
//' @export
// [[Rcpp::export]]
double getSlope(NumericVector xCoordinates, NumericVector yCoordinates) {
return (yCoordinates[1] - yCoordinates[0]) / (xCoordinates[1] - xCoordinates[0]);
}
I do not have any deeper knowledge in Rcpp or c++. I read the Vignette and Writing a package that uses Rcpp I think I also read the right parts but I didn't get it.
Why is the getSlope function not "visible" in the other function - as they are both in the same package. How can I use the getSlope in the other file?
Sorry but I am really stuck.
Thanks and best Regards
Nico