
Contents
実行環境 ファイルの例 R で、NULL 文字をスキップして 1 行ずつベクトルに入れる ファイル読み込みで失敗した例(ここまで、昨日の「読み込み」編) - 昨日のダミーファイルを作るスクリプト
- 準備:R
で空ファイルや NULL 文字だけのファイルを作る - できたファイルと、昨日
DOS で出力したもの(終端に 0x1A)の比較 - ファイル連結を
DOS で行う場合
昨日のダミーファイルを作るスクリプト
tmp1 = 'R:/TMP/tmp1.prn' tmp2 = 'R:/TMP/tmp2.prn' out1 = 'R:/TMP/all_no_null.prn' out2 = 'R:/TMP/all.prn' file.create(out1) file.create(out2) for (i in 1:9) { str = paste(collapse=' ', rep(i, 10)) write(str, tmp1) writeBin(paste(sep='', str, '\n'), tmp2) file.append(out1, tmp1) file.append(out2, tmp2) } file.remove(c(tmp1, tmp2))

処理を頼まれたテキストファイルの各行末に
準備:R で空ファイルや NULL 文字だけのファイルを作る
空ファイルは単純に# create an empty file file.create(filename) # create a file including 0x00 only writeBin('', filename)
文字列を
できたファイルと、昨日 DOS で出力したもの(終端に 0x1A)の比較
まず
次に



昨日・今日のファイルを


メモ帳では ↓ ファイル終端に


ファイル連結を DOS で行う場合
tmp1 = 'R:\\TMP\\tmp1.prn' tmp2 = 'R:\\TMP\\tmp2.prn' out1 = 'R:\\TMP\\all_no_null.prn' out2 = 'R:\\TMP\\all.prn' file.create(out1) file.create(out2) for (i in 1:9) { str = paste(collapse=' ', rep(i, 10)) write(str, tmp1) writeBin(paste(sep='', str, '\n'), tmp2) system(paste('cmd /c copy /b', out1, '+', tmp1, out1)) # require /b system(paste('cmd /c copy /b', out2, '+', tmp2, out2)) } file.remove(c(tmp1, tmp2))
昨日は
なお


