yuanfan
啊,我写了一篇博客,整理了本帖里面提到的方法https://yuanfan.rbind.io/project/r-paste/。
写的时候突然想到 R 里面是不是也会有 Linux 的 cat,于是乎多写了一个方法四,即用 scan 和 cat 函数来读取和导出。但是这个方法有一个细节不够完善,就是用 cat 函数导出的时候,如果只设定fill = TRUE
的话,有些本应多行的会连成一行,但是再加上sep = '\n'
的话,不会出现多行连成一行的情况,可是同时会导致本来正常换行的行之间多出一行。
举个栗子。正常应该导出下面这样的。
select a.col1,
b.col2
from table1 a
join table2 b on a.id=b.id
如果 cat 函数里设置fill = TRUE
,会出现下面这种多行合为一行的。
select a.col1, b.col2
from table1 a
join table2 b on a.id=b.id
如果再加上sep = '\n'
,又会变成下面这样。
select a.col1,
b.col2
from table1 a
join table2 b on a.id=b.id