0
爲什麼帶\n
換行符的Rcpp函數發送到Rcpp::Rcout
未編譯?cpp功能:編譯Rcout <<「換行符 n」
這工作
cppFunction('void testing() {Rcout<<"hello"<<std::endl;}')
testing()
# hello
但這並不
cppFunction('void testing() {Rcout<<"hello\n";}')
爲什麼帶\n
換行符的Rcpp函數發送到Rcpp::Rcout
未編譯?cpp功能:編譯Rcout <<「換行符 n」
這工作
cppFunction('void testing() {Rcout<<"hello"<<std::endl;}')
testing()
# hello
但這並不
cppFunction('void testing() {Rcout<<"hello\n";}')
的r串在逃避自己的方式越來越。請嘗試:
cppFunction('void testing() {Rcout<<"hello\\n";}')
請注意雙\\
。您不想將文字新行傳送到生成的C++腳本,而是想自己發送字符\n
- 因此,您需要跳過\
。
要避免這樣的問題,您應該更喜歡使用屬性界面 - 請參見Rcpp-attributes。
請注意,如果您嘗試運行cppFunction('void testing() {Rcout<<"hello\n";}', verbose=TRUE)
,則此錯誤會變得更加明顯 - 您可以看到生成的腳本具有文字換行符而不是\n
字符。