【问题标题】:How to get latest RStudio version如何获取最新的 RStudio 版本
【发布时间】: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 是开源的,所以解决方案就在那里。
  • 对,现在你解释清楚了:)

标签: r bash xpath rstudio


【解决方案1】:

您似乎可以从 url http://download1.rstudio.org/current.ver 获得最新的稳定版本号,并且它是最新的(出于某种未知原因),至少在撰写此答案时是这样。

$ curl -s http://download1.rstudio.org/current.ver 1.1.447

$ curl -s https://www.rstudio.org/links/check_for_update?version=1.0.0 | grep -oEi 'update-version=([0-9]+\.[0-9]+\.[0-9]+)' | awk -F= '{print $2}' 1.1.423

在这里找到:https://github.com/yutannihilation/ansible-playbook-r/blob/master/tasks/install-rstudio-server.yml

【讨论】:

    【解决方案2】:

    如果您使用版本字符串查询 RStudio 的 check_for_update,您将返回更新版本和获取它的 URL:

    https://www.rstudio.org/links/check_for_update?version=1.0.0

    update-version=1.0.153&update-url=https%3A%2F%2Fwww.rstudio.com%2Fproducts%2Frstudio%2Fdownload%2F&update-message=RStudio%201.0.153%20is%20now%20available%20%28you %27re%20using%201.0.0%29&update-urgent=0

    看这里:

    https://github.com/rstudio/rstudio/blob/54cd3abcfc58837b433464c793fe9b03a87f0bb4/src/cpp/session/modules/SessionUpdates.R

    如果你真的想从下载页面抓取它,那么我会在“下载”类的第一个 &lt;table&gt; 的第一个 &lt;td&gt; 中获得 href&lt;a&gt;,然后解析出来“RStudio-”和“.exe”之间的三个点分隔数字。 RStudio 在所有平台上发布版本,因此从 Windows 下载中获取它就足够了。

    > url = "https://www.rstudio.com/products/rstudio/download/"
    > thepage<-xml2::read_html(url)
    > html_node(thepage, ".downloads td a") %>% html_attr("href")
    [1] "https://download1.rstudio.org/RStudio-1.0.153.exe"
    

    【讨论】:

    • 这是我选择的单线:stringr::str_match(scan("https://www.rstudio.org/links/check_for_update?version=1.0.0", what = character(0)), '^[^=]+=([^\\&amp;]+)\\&amp;.*')[[2]]
    【解决方案3】:

    这里有一个几乎解决方案:

    https://hub.docker.com/r/rocker/rstudio-daily/~/dockerfile/

    在这个脚本中,它会抓取最新版本:

    https://raw.githubusercontent.com/rocker-org/rstudio-daily/master/latest.R

    您需要修改该脚本,使其接受的内容更加严格,即我想要这个rstudio-server-1.1.355-amd64.deb 而不是stretch 变体。

    (但无论如何,您都可以修改它以针对您想要的构建类型,这是日常构建,RStudio Server for Ubuntu。)

    【讨论】:

    • 谢谢。您放置的即时链接用于 RStudio(服务器)的日常构建,但这很容易修复。对于稳定的 RStudio(服务器),他们使用 RSTUDIO_LATEST=$(wget --no-check-certificate -qO- https://s3.amazonaws.com/rstudio-server/current.ver)
    • 您提议的真正问题是rocker 仅服务于 RStudio-server,因为它们使用 docker 容器并且从不费心封装 GUI 应用程序。而且我已经有一个网络抓取脚本来读取当前的 RStudio-server 版本。
    【解决方案4】:

    如果有人感兴趣,这里是我的终极 RServer-desktop-on-Ubuntu 更新脚本。它会安装RStudio-desktop 64bit,然后,如果Fira Console 字体可用,则为RStudio 应用来自https://github.com/tonsky/FiraCode/wiki/RStudio-instructions 的补丁,因此连字开始工作。

    #!/bin/bash
    if dpkg -s rstudio >/dev/null 2>/dev/null; then
        ver=$(apt show rstudio | grep Version)
        pattern='^Version: ([0-9.]+)\s*$'
        if [[ $ver =~ $pattern ]]; then
            ourversion=${BASH_REMATCH[1]}
            netversion=$(Rscript -e 'cat(stringr::str_match(scan("https://www.rstudio.org/links/check_for_update?version=1.0.0", what = character(0), quiet=TRUE), "^[^=]+=([^\\&]+)\\&.*")[[2]])')
            if [[ $ourversion != $netversion ]]; then
                RSTUDIO_URI=$(Rscript /tmp/get_rstudio_uri.R)
            fi
            tee /tmp/get_rstudio_uri.R <<EOF
    if(!require('rvest')) install.packages('rvest', repos='http://cran.us.r-project.org')
    xpath='.downloads:nth-child(2) tr:nth-child(5) a'
    url = "https://www.rstudio.com/products/rstudio/download/"
    thepage<-xml2::read_html(url)
    cat(html_node(thepage, xpath) %>% html_attr("href"))
    EOF
            RSTUDIO_URI=$(Rscript /tmp/get_rstudio_uri.R)
    
            wget -c --output-document /tmp/rstudio.deb $RSTUDIO_URI 
            sudo dpkg -i /tmp/rstudio.deb
            rm /tmp/rstudio.deb
            rm /tmp/get_rstudio_uri.R
    
            if fc-list |grep -q FiraCode; then
                if !grep -q "text-rendering:" /usr/lib/rstudio/www/index.htm; then
                    sudo sed -i '/<head>/a<style>*{text-rendering: optimizeLegibility;}<\/style>' /usr/lib/rstudio/www/index.htm
                fi
            fi
        fi
    fi
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-02
      • 1970-01-01
      • 1970-01-01
      • 2011-09-14
      • 1970-01-01
      • 2015-03-15
      • 1970-01-01
      • 2017-04-17
      相关资源
      最近更新 更多