4). tidy.eval: 输出格式化的R代码和运行结果
以字符串形式,执行R脚本
> tidy.eval(text = c("a<-1+1;a", "matrix(rnorm(10),5)"))a <- 1 + 1a## [1] 2matrix(rnorm(10), 5)## [,1] [,2]## [1,] 0.65050729 0.1725221## [2,] 0.05174598 0.3434398## [3,] -0.91056310 0.1138733## [4,] 0.18131010 -0.7286614## [5,] 0.40811952 1.82883465). usage: 格式化函数定义,并按指定宽度输出
> varfunction (x, y = NULL, na.rm = FALSE, use){if (missing(use))use <- if (na.rm)"na.or.complete"else "everything"na.method <- pmatch(use, c("all.obs", "complete.obs", "pairwise.complete.obs","everything", "na.or.complete"))if (is.na(na.method))stop("invalid 'use' argument")if (is.data.frame(x))x <- as.matrix(x)else stopifnot(is.atomic(x))if (is.data.frame(y))y <- as.matrix(y)else stopifnot(is.atomic(y)).Call(C_cov, x, y, na.method, FALSE)}<bytecode: 0x0000000008fad030><environment: namespace:stats>> usage(var)var(x, y = NULL, na.rm = FALSE, use)usage函数,只输出函数的定义。
> usage(lm,width=30)lm(formula, data, subset, weights, na.action, method = "qr", model = TRUE, x = FALSE, y = FALSE, qr = TRUE, singular.ok = TRUE, contrasts = NULL, offset, ...)usage的width参数,控制函数的显示宽度。
6). tidy.gui: GUI工具,编辑并格式化R代码
安装gWidgetsRGtk2库
> install.packages("gWidgetsRGtk2")also installing the dependencies ‘RGtk2’, ‘gWidgets’trying URL 'http://mirror.bjtu.edu.cn/cran/bin/windows/contrib/3.0/RGtk2_2.20.25.zip'Content type 'application/zip' length 13646817 bytes (13.0 Mb)opened URLdownloaded 13.0 Mbtrying URL 'http://mirror.bjtu.edu.cn/cran/bin/windows/contrib/3.0/gWidgets_0.0-52.zip'Content type 'application/zip' length 1212449 bytes (1.2 Mb)opened URLdownloaded 1.2 Mbtrying URL 'http://mirror.bjtu.edu.cn/cran/bin/windows/contrib/3.0/gWidgetsRGtk2_0.0-82.zip'Content type 'application/zip' length 787592 bytes (769 Kb)opened URLdownloaded 769 Kbpackage ‘RGtk2’ successfully unpacked and MD5 sums checkedpackage ‘gWidgets’ successfully unpacked and MD5 sums checkedpackage ‘gWidgetsRGtk2’ successfully unpacked and MD5 sums checked打开GUI控制台
> library("gWidgetsRGtk2")> g = tidy.gui()我们输入一段不太好看的代码:
点击“转换”
在GUI的编辑器中,R语言的代码被格式化了! |