R语言cat函数一般操作
2019-04-27 本文已影响0人
医科研
iter <- stats::rpois(1, lambda = 10)
## print an informative message
cat("iteration = ", iter <- iter + 1)##
## iteration = 13
cat("iteration = ", iter <- iter + 1, "\n")##
## iteration = 14
cat("iteration = ", "\n" ,iter <- iter + 1)##换行位置在\n之后
## iteration =
## 15
##
print("iteration = ", iter <- iter + 1)##
## [1] "iteration = "
print("iteration = ")##
## [1] "iteration = "
## 'fill' and label lines:
cat(paste(letters, 100* 1:26), fill = TRUE, labels = paste0("{", 1:10, "}:"))
## {1}: a 100 b 200 c 300 d 400 e 500 f 600 g 700 h 800 i 900 j 1000 k 1100
## {2}: l 1200 m 1300 n 1400 o 1500 p 1600 q 1700 r 1800 s 1900 t 2000 u 2100
## {3}: v 2200 w 2300 x 2400 y 2500 z 2600
##
cat("file A\n", file = "A")##打印到文件
cat("file B\n", file = "B")
file.append("A", "B")#
## [1] TRUE
file.create("A") # (trashing previous,新建文件夹
## [1] TRUE
file.append("A", rep("B", 10))
## [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
if(interactive()) file.show("A") # -> the 10 lines from 'B'
file.copy("A", "C")
## [1] TRUE
dir.create("tmp")
file.copy(c("A", "B"), "tmp")##复制文件到"temp"文件
## [1] TRUE TRUE
list.files("tmp") # -> "A" and "B"
## [1] "A" "B"
unlink("tmp", recursive = TRUE)
file.remove("A", "B", "C")##
## [1] TRUE TRUE TRUE