【发布时间】:2018-05-06 06:59:47
【问题描述】:
我正在努力编写一个脚本,该脚本会以某种方式从 https://www.rstudio.com/products/rstudio/download/ 中获取最新 RStudio 版本的编号,下载并安装它。
由于我是一名 R 程序员,我开始使用 rvest 包编写 R 脚本。我设法抓取了 RStudio 服务器的下载链接,但我仍然无法获取 RStudio 本身。
这里是获取 Ubuntu 的 64 位 RStudio-server 下载链接的 R 代码。
if(!require('stringr')) install.packages('stringr', Ncpus=8, repos='http://cran.us.r-project.org')
if(!require('rvest')) install.packages('rvest', Ncpus=8, repos='http://cran.us.r-project.org')
xpath<-'//code[(((count(preceding-sibling::*) + 1) = 3) and parent::*)]'
url<-'https://www.rstudio.com/products/rstudio/download-server/'
thepage<-xml2::read_html(url)
the_links_html <- rvest::html_nodes(thepage,xpath=xpath)
the_links <- rvest::html_text(the_links_html)
the_link <- the_links[stringr::str_detect(the_links, '-amd64\\\\.deb')]
the_r_uri<-stringr::str_match(the_link, 'https://.*$')
cat(the_r_uri)
不幸的是,RStudio 桌面下载页面的布局完全不同,我同样的方法在这里不起作用。
有人可以帮我解决这个问题吗?我不敢相信,世界上所有的数据科学家都手动升级了他们的 RStudio!
还有一个更简单的脚本版本,它读取 RStudio-server 的版本。 Bash 版本:
RSTUDIO_LATEST=$(wget --no-check-certificate -qO- https://s3.amazonaws.com/rstudio-server/current.ver)
或 R 版本:
scan('https://s3.amazonaws.com/rstudio-server/current.ver', what = character(0))
但是 RStudio-desktop 的版本仍然让我难以理解。
【问题讨论】:
-
R Studio 在您运行时是否不检查自身是否有更新?
-
是的,这是一个可配置的选项——但这不是这里所要求的。
-
@mdsumner 是的,但是 RStudio 是开源的,所以解决方案就在那里。
-
对,现在你解释清楚了:)