[Rcpp-devel] Using printf: Error in source("/tmp/printf.r") : /tmp/printf.r:8:11: unexpected input
This has nothing to do with printf, this is simply because you use double quotes 'inside' double quotes, replace the outer quotes by single quotes and you should be fine. Please also note that Rprintf is preferred, because it will work on all platforms or user interfaces. Hope this helps, Romain Le 18/11/11 20:32, Paul Menzel a ?crit :
Dear Rcpp folks,
could you please give me a hint on how to use `printf`.
library(inline)
inc<- "
#include<stdio.h>
"
drucken<-cxxfunction(includes=inc, plugin="Rcpp", body="
unsigned int length = 1;
printf("%u\\n", length);
return wrap(length);
")
throws the following error, when I try to source it.
> source("/tmp/printf.r")
Error in source("/tmp/printf.r") : /tmp/printf.r:8:11: unexpected input
7: unsigned int length = 1;
8: printf("%u\\n", length);
Removing the `printf` statement gets rid of the error. I tested the
standalone example and `gcc` does not complain.
/* printf example */
#include<stdio.h>
int main()
{
unsigned int length = 1;
printf("%u \n", length);
return length;
}
Probably my mistake is a simple one because
source("/usr/lib/R/site-library/Rcpp/examples/RcppInline/RcppInlineWithLibsExamples.r")
works and `printf` statements are used in there. (I had to install `libgsl0-dev` to get the headers.) Thanks, Paul
_______________________________________________ Rcpp-devel mailing list Rcpp-devel at lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Romain Francois Professional R Enthusiast http://romainfrancois.blog.free.fr -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20111118/74b36975/attachment.htm>