呼び出しをラップして区切り記号として指定することにより、 の出力の表面的な改善をsystem
得ることができます。これにより、文字ベクトルの既定である空白で区切られる代わりに、別の行に出力が表示されます。これは、改行で区切られていないと出力の形式がほとんど意味をなさないため、 のようなコマンドに非常に役立ちます。cat
'\n'
tree
という名前のサンプル ディレクトリについて、以下を比較してくださいtest
。
バッシュ
$ tree test
test
├── A1.tif
├── A2.tif
├── A3.tif
├── README
└── src
├── sample.R
└── sample2.R
1 directory, 6 files
Jupyter Notebook の R
system
のみ、出力を理解するのが難しい:
> system('tree test', intern=TRUE)
'test' '├── A1.tif' '├── A2.tif' '├── A3.tif' '├── README' '└── src' ' ├── sample.R' ' └── sample2.R' '' '1 directory, 6 files
cat
+ system
、出力は bash で次のようになります。
> cat(system('tree test', intern=TRUE), sep='\n')
test
├── A1.tif
├── A2.tif
├── A3.tif
├── README
└── src
├── sample.R
└── sample2.R
1 directory, 6 files
のようなコマンドの場合ls
、上記は、出力が通常 bash のスペースで区切られる改行を導入することに注意してください。
入力を節約する関数を作成できます。
> # "jupyter shell" function
> js <- function(shell_command){
> cat(system(shell_command, intern=TRUE), sep='\n')
> }
>
> # brief syntax for shell commands
> js('tree test')