最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】运行R语言出错:Error: could not find function "getURL"

R crifan 11965浏览 0评论

【背景】

折腾:

【记录】尝试用R语言去试试抓取网页和提取信息

期间,直接去运行代码:

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"

如图:

r 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的镜像。

choose CRAN mirror for r

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 lan install rcurl and bitops done

 

【总结】

可以通过R语言的自带GUI工具中输入命令:

chooseCRANmirror()
install.packages("RCurl")

而自动帮我们选择镜像(自己选)和安装对应的库的。

转载请注明:在路上 » 【已解决】运行R语言出错:Error: could not find function "getURL"

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
90 queries in 0.106 seconds, using 20.53MB memory