Print to the console
You can use Rprintf() to print formatted output to the console. It is similar to the sprintf() function in R, and uses the format specifiers:
%dto specify an integer%sto specify a string
Latihan ini adalah bagian dari kursus
Optimizing R Code with Rcpp
Petunjuk latihan
Write a function that adds two integers (x and y) and prints the following message about it:
** <x> + <y> = <x + y>
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# Define the function add()
cppFunction('
int add(int x, int y) {
int res = x + y ;
___("** %d + ___ = ___\\n", x, y, res) ;
return res ;
}
')
# Call add() to print THE answer
add(40, 2)