Error when attempting to install torch for R package

Install the required dependencies before installing torch for R.

Written by jairo.prado

Last published at: March 19th, 2025

Problem

When attempting to install the package torch for R in compute using Databricks Runtime 16.1 ML, you encounter an error indicating certain dependencies are missing.  

ERROR: dependencies ‘coro’, ‘safetensors’ are not available for package ‘torch’ * removing ‘/usr/local/lib/R/site-library/torch’

 

Cause

Not all libraries required by a package are installed by default. 

 

Solution

Use the following code to install the required dependencies before installing torch for R.  

%sh
# Download the file using wget and save it to /tmp
wget -O /tmp/torch_0.13.0.9001.tar.gz "https://github.com/s-u/torch/releases/download/e93430/torch_0.13.0.9001.tar.gz"

%r
install.packages(c("coro", "safetensors"))

%r
install.packages("/tmp/torch_0.13.0.9001.tar.gz", repos = NULL, type = "source")

%r
library(torch)