求助,R语言的GUI编程方面

Python015

求助,R语言的GUI编程方面,第1张

harts包安装 require(devtools) install_github('rCharts', 'ramnathv') rCharts函数像lattice函数通formula、data指定数据源绘图式并通type指定图表类型 面通例解其工作原理我鸢尾花数据集例

IDE Drive UDMA 支持UDMA的IDE驱动器:使用该选项可以启用或禁用通过内部IDE硬盘接口的DMA传输。

一、 安装RODBC库

1、进入R语言的GUI界面(RGUI.EXE),在菜单栏选择“程序包/安装程序包

2、在弹出的窗口里往下拉,选择RODBC如图,点击确定

3、在ODBC数据源管理器里将需要的数据库添加进去,这里笔者使用的是SQL Server2008,驱动程序选择Native Client10.0

3、在R语言窗口输入连接语句

>library(RODBC)

**这里是载入RODBC库

>channel<-odbcConnect("MyTest",uid="ripley",case="tolower")

**连接刚才添加进数据源的“MyTest”数据库

**ch <- odbcConnect("some dsn ", uid = "user ", pwd = "**** ")

**表示用户名为user,密码是****,如果没有设置,可以直接忽略

>data(USArrests)

**将“USArrests”表写进数据库里(这个表是R自带的)

>sqlSave(channel,USArrests,rownames = "state",addPK = TRUE)

**将数据流保存,这时候打开SQL Server就可以看到新建的USArrests表了

>rm(USArrests)

>sqlTables(channel)

**给出数据库中的表

>sqlFetch(channel,"USArrests",rownames = "state")

**输出USArrests表中的内容

>sqlQuery(channel,"select * from USArrests")

**调用SELECT查询语句并返回结果(如图)

>sqlDrop(channel,"USArrests")

**删除表

>odbcClose(channel)

**最后要记得关闭连接

当然,通过这个办法也可以读取Excel、Access表中的内容,具体方法类似,这里不再重复

命令代码参考如下:

# An R function to clear the screen on RGui:

cls <- function() {

if (.Platform$GUI[1] != "Rgui")

return(invisible(FALSE))

if (!require(rcom, quietly = TRUE)) # Not shown any way!

stop("Package rcom is required for 'cls()'")

wsh <- comCreateObject("Wscript.Shell")

if (is.null(wsh)) {

return(invisible(FALSE))

} else {

comInvoke(wsh, "SendKeys", "\014")

return(invisible(TRUE))

}

}

#cls() # test

# If you want to make sure that it worked (well, not 100% sure, but...)

res <- cls()

if (res) cat("Console should be cleared now!\n")