如下:
> install.packages("sqldf")
> library(sqldf)
载入需要的程辑包:gsubfn
载入需要的程辑包:proto
载入需要的程辑包:RSQLite
载入需要的程辑包:DBI
载入需要的程辑包:RSQLite.extfuns
警告信息:
In fun(libname, pkgname) : 没有DISPLAY变量,因此没有Tk这个功能 ( no DISPLAY variable so Tk is not available)
> q()
设置DISPLAY环境变量后,虽然加载包时没警告显示,但仍然有问题
# export DISPLAY=10.1.5.241:0.0
R
> library(sqldf)
> a <- sqldf("select sum(dist) from cars")
Loading required package: tcltk
错误于structure(.External(.C_dotTcl, ...), class = "tclObj") :
[tcl] unknown math function "min".
解决办法:
使用R较低的引擎
#make sure your gsubfn version is gsubfn 0.6-4 or later
> packageVersion("gsubfn")
[1] ‘0.6.6‘
> options(gsubfn.engine = "R")
> library("sqldf")
> a <- sqldf("select sum(dist) from cars")
> sqldf("select * from iris limit 5")
Sepal_Length Sepal_Width Petal_Length Petal_Width Species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 3.0 1.4 0.2 setosa
3 4.7 3.2 1.3 0.2 setosa
4 4.6 3.1 1.5 0.2 setosa
5 5.0 3.6 1.4 0.2 setosa