Oefenweb / ansible-r

Ansible role to set up (the latest version of) R in Ubuntu systems
MIT License
44 stars 27 forks source link

Updating packages via R-update-package is broken #58

Open paulkitt opened 8 months ago

paulkitt commented 8 months ago

When updating packages via the role the 'R-update-package' results in this error:

failed: [... (item={'name': 'psych', 'type': 'cran', 'state': 'updated'}) => changed=false 
  ansible_loop_var: item
  cmd:
  - /usr/local/bin/R-update-package
  - psych
  - cran
  - /usr/local/lib/R/site-library
  delta: '0:00:01.354098'
  end: '2024-04-02 11:24:04.696954'
  item:
    name: psych
    state: updated
    type: cran
  msg: non-zero return code
  rc: 1
  start: '2024-04-02 11:24:03.342856'
  stderr: |-
    Error in download.file(url = paste0(repos, "/PACKAGES.rds"), destfile = dest,  :
      downloaded length 0 != reported length 0
    Calls: withCallingHandlers ... tryCatchList -> tryCatchOne -> doTryCatch -> download.file
    Execution halted
  stderr_lines: <omitted>
  stdout: ''
  stdout_lines: <omitted>

I tried to use the R update script directly resulting in the same problem:

./R-update-package psych cran /usr/local/lib/R/site-library 
Error in download.file(url = paste0(repos, "/PACKAGES.rds"), destfile = dest,  : 
  downloaded length 0 != reported length 0
Calls: withCallingHandlers ... tryCatchList -> tryCatchOne -> doTryCatch -> download.file
Execution halted
paulkitt commented 8 months ago

I tried to figure out how to fix the script but failed with lacking the knowledge about R and RScript. Would be amazing if anybody could write a fix/submit a mr. Its a great role and we are happy that we found it.

tersmitten commented 7 months ago

I'll have a look when I find some time. What's the OS / version you are using?

paulkitt commented 7 months ago

Amazing thanks a lot! We are deploying the role to Ubuntu 22.04

tersmitten commented 7 months ago

Can you attach te "configuration" you're using? Otherwise it is a bit difficult to replicate your results :-)

paulkitt commented 7 months ago

Yes sure. I replicated the problem inside the molecule test:

  1. Update molecule converge and run molecule
    ---
    - name: Converge
    hosts: all
    become: true
    vars:
    r_packages:
      - name: yaml
        state: updated
    roles:
    - ../../../
  2. Install older version of cran pkt
    molecule login
    R
    packageurl <- "https://cran.r-project.org/src/contrib/Archive/yaml/yaml_2.3.7.tar.gz"
    install.packages(packageurl, repos=NULL, type="source")
  3. Run Molecule again to update the pkt

Error:

TASK [../../../ : packages | update] *******************************************
failed: [instance] (item={'name': 'yaml', 'state': 'updated'}) => {"ansible_loop_var": "item", "changed": false, "cmd": ["/usr/local/bin/R-update-package", "yaml", "cran", "/usr/local/lib/R/site-library"], "delta": "0:00:02.106649", "end": "2024-04-11 12:58:32.121181", "item": {"name": "yaml", "state": "updated"}, "msg": "non-zero return code", "rc": 1, "start": "2024-04-11 12:58:30.014532", "stderr": "Error in download.file(url = paste0(repos, \"/PACKAGES.rds\"), destfile = dest,  : \n  cannot open URL 'https://cran.rstudio.com/PACKAGES.rds': HTTP status was '404 Not Found'\nCalls: withCallingHandlers ... tryCatchList -> tryCatchOne -> doTryCatch -> download.file\nExecution halted", "stderr_lines": ["Error in download.file(url = paste0(repos, \"/PACKAGES.rds\"), destfile = dest,  : ", "  cannot open URL 'https://cran.rstudio.com/PACKAGES.rds': HTTP status was '404 Not Found'", "Calls: withCallingHandlers ... tryCatchList -> tryCatchOne -> doTryCatch -> download.file", "Execution halted"], "stdout": "", "stdout_lines": []}
tersmitten commented 7 months ago

The output already reveals the issue:

cannot open URL 'https://cran.rstudio.com/PACKAGES.rds': HTTP status was '404 Not Found'
tersmitten commented 7 months ago

Can you try configuring it like this?

---
- name: Converge
  hosts: all
  become: true
  vars:
    r_cran_mirror: https://cloud.r-project.org/
    r_packages:
      - name: yaml
        state: updated
  roles:
    - ../../../
paulkitt commented 7 months ago

Changing the r_cran_mirror results in the same problem:

failed: [instance] (item={'name': 'yaml', 'state': 'updated'}) => {"ansible_loop_var": "item", "changed": false, "cmd": ["/usr/local/bin/R-update-package", "yaml", "cran", "/usr/local/lib/R/site-library"], "delta": "0:00:01.149067", "end": "2024-04-18 13:16:36.394198", "item": {"name": "yaml", "state": "updated"}, "msg": "non-zero return code", "rc": 1, "start": "2024-04-18 13:16:35.245131", "stderr": "Error in download.file(url = paste0(repos, \"/PACKAGES.rds\"), destfile = dest,  : \n  cannot open URL 'https://cloud.r-project.org/PACKAGES.rds': HTTP status was '404 Not Found'\nCalls: withCallingHandlers ... tryCatchList -> tryCatchOne -> doTryCatch -> download.file\nExecution halted", "stderr_lines": ["Error in download.file(url = paste0(repos, \"/PACKAGES.rds\"), destfile = dest,  : ", "  cannot open URL 'https://cloud.r-project.org/PACKAGES.rds': HTTP status was '404 Not Found'", "Calls: withCallingHandlers ... tryCatchList -> tryCatchOne -> doTryCatch -> download.file", "Execution halted"], "stdout": "", "stdout_lines": []}

I tried to make sense of the R-update-package r-script but didnt understand why there this url is called and why it is brocken. I really like the approach to install the packages directly via R and via apt. Would be great to find a fix.

paulkitt commented 7 months ago

Are the Rscripts included in the role part of a lager project where I could ask for support to fix the issue?

tersmitten commented 2 months ago

@paulkitt No, unfortunately not