【背景】
折腾:
期间,直接去运行代码:
retHtml <- getURL("http://www.yiteng365.com/commodity.do?id=5708&ispng=")
结果出错:
> retHtml <- getURL("http://www.yiteng365.com/commodity.do?id=5708&ispng=") Error: could not find function "getURL" |
如图:
【解决过程】
1.参考:
Dimitrios Kouzis-Loukas’ Blog – Running R from Cygwin with RCurl
去试试:
> require('RCurl') Loading required package: RCurl Warning message: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘RCurl’
结果是找不到无法加载RCurl。
2.继续去试试:
> chooseCRANmirror()
然后选择对应的China(HeFei)应该是USTC的镜像。
3.再继续去安装:
install.packages("RCurl")
稍等即可安装好:
> require('RCurl') Loading required package: RCurl Warning message: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘RCurl’ > chooseCRANmirror() > install.packages("RCurl") also installing the dependency ‘bitops’ trying URL 'http://mirrors.ustc.edu.cn/CRAN/bin/windows/contrib/3.0/bitops_1.0-6.zip' Content type 'application/zip' length 35878 bytes (35 Kb) opened URL downloaded 35 Kb trying URL 'http://mirrors.ustc.edu.cn/CRAN/bin/windows/contrib/3.0/RCurl_1.95-4.1.zip' Content type 'application/zip' length 2836490 bytes (2.7 Mb) opened URL downloaded 2.7 Mb package ‘bitops’ successfully unpacked and MD5 sums checked package ‘RCurl’ successfully unpacked and MD5 sums checked The downloaded binary packages are in C:\Users\CLi\AppData\Local\Temp\RtmpIRchyS\downloaded_packages >
然后再去试试就可以了:
> require('RCurl') Loading required package: RCurl Loading required package: bitops
如图:
【总结】
可以通过R语言的自带GUI工具中输入命令:
chooseCRANmirror() install.packages("RCurl")
而自动帮我们选择镜像(自己选)和安装对应的库的。
转载请注明:在路上 » 【已解决】运行R语言出错:Error: could not find function "getURL"