String 阻止R将尾随空格写入保存的字符串

String 阻止R将尾随空格写入保存的字符串,string,r,svg,String,R,Svg,我正在创建一个.svg文件,通过paste()将字符串粘贴到R中。之后,我通过writeChar()将字符串写入文件。问题是R似乎在文件末尾添加了空格字符\R\n。这使得.svg文件无效。谷歌Chrome抱怨说 This page contains the following errors: error on line 71 at column 1: Extra content at the end of the document Below is a rendering of the pag

我正在创建一个.svg文件,通过paste()将字符串粘贴到R中。之后,我通过
writeChar()
将字符串写入文件。问题是R似乎在文件末尾添加了空格字符
\R\n
。这使得.svg文件无效。谷歌Chrome抱怨说

This page contains the following errors:

error on line 71 at column 1: Extra content at the end of the document
Below is a rendering of the page up to the first error.
我想在Anki中使用.svg文件,Anki完全拒绝渲染它们。Inkscape使它们很好


是否有方法阻止R在文件末尾添加
\R\n

如果
x
是您的字符串,一种方法是:

writeBin(charToRaw(x), 'out')
或者更好

writeChar(x, 'out', eos=NULL)
但您也可以只使用
cat

cat(x, file='out')