#include <stdio.h>
main(void)
{
printf("Computer in Physics\n");
}
#include <stdio.h>
#include <Rcpp.h>
using namespace Rcpp;
CharacterVector sample01()
{
CharacterVector x = "Computer in Physics\n";
return x;
}
> g++ sample01.cpp -o sample01
> sample01
Computer in Physics
> sourceCpp("sample01R.cpp",verbose=TRUE)
Generated extern "C" functions
--------------------------------------------------------
// sample01
CharacterVector sample01();
RcppExport SEXP sourceCpp_97064_sample01() {
BEGIN_RCPP
Rcpp::RObject __result;
Rcpp::RNGScope __rngScope;
__result = Rcpp::wrap(sample01());
return __result;
END_RCPP
}
Generated R functions
-------------------------------------------------------
`.sourceCpp_97064_DLLInfo` <- dyn.load('C:/Users/ryamada/AppData/Local/Temp/RtmpCiGfLb/sourcecpp_1c944b1a35c5/sourceCpp_37015.dll')
sample01 <- Rcpp:::sourceCppFunction(function() {}, FALSE, `.sourceCpp_97064_DLLInfo`, 'sourceCpp_97064_sample01')
rm(`.sourceCpp_97064_DLLInfo`)
Building shared library
--------------------------------------------------------
DIR: C:/Users/ryamada/AppData/Local/Temp/RtmpCiGfLb/sourcecpp_1c944b1a35c5
C:/PROGRA~1/R/R-31~1.0/bin/x64/R CMD SHLIB -o "sourceCpp_37015.dll" "" "sample01R.cpp"
g++ -m64 -I"C:/PROGRA~1/R/R-31~1.0/include" -DNDEBUG -I"C:/Users/ryamada/Documents/R/win-library/3.1/Rcpp/include" -I"c:/Users/ryamada/Desktop/Rcpp" -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O2 -Wall -mtune=core2 -c sample01R.cpp -o sample01R.o
g++ -m64 -shared -s -static-libgcc -o sourceCpp_37015.dll tmp.def sample01R.o -Ld:/RCompile/CRANpkg/extralibs64/local/lib/x64 -Ld:/RCompile/CRANpkg/extralibs64/local/lib -LC:/PROGRA~1/R/R-31~1.0/bin/x64 -lR
> sample01()
[1] "Computer in Physics\n"
#include <stdio.h>
main(void)
{
int a, b, c;
a=1;
b=2;
c=a+b;
printf(" %d + %d = %d \n", a, b, c );
}
#include <stdio.h>
#include <Rcpp.h>
using namespace Rcpp;
int sample02(int a, int b)
{
int c=a+b;
return c;
}
- その3 double の計算、doubleのベクトルを返す
#include <stdio.h>
#include <math.h>
main(void)
{
double a, b, c;
double xp, xm;
a = 1.0;
b = -4.0;
c = 2.0;
xp = (-b + sqrt(b*b-4.0*a*c))/(2.0*a);
xm = (-b - sqrt(b*b-4.0*a*c))/(2.0*a);
printf("The solutions are %lf and %lf\n", xp, xm );
}
#include <stdio.h>
#include <math.h>
#include <Rcpp.h>
using namespace Rcpp;
NumericVector sample03(double a, double b, double c)
{
double xp, xm;
xp = (-b + sqrt(b*b-4.0*a*c))/(2.0*a);
xm = (-b - sqrt(b*b-4.0*a*c))/(2.0*a);
NumericVector x = NumericVector::create(xp,xm);
return(x);
}