安装 rJava 和 RJDBC 库Install rJava and RJDBC libraries

本文介绍如何安装 rJava 和 RJBDC 库。This article explains how to install rJava and RJBDC libraries.

问题Problem

在笔记本单元中使用以下命令安装 rJava 和 RJDBC 库时:When you install rJava and RJDBC libraries with the following command in a notebook cell:

install.packages(c("rJava", "RJDBC"))

你将看到以下错误:You observe the following error:

ERROR: configuration failed for package 'rJava'

原因Cause

RJava 和 RJDBC 包检查 Azure Databricks R 目录中不存在的 Java 依赖项和文件路径。The rJava and RJDBC packages check for Java dependencies and file paths that are not present in the Azure Databricks R directory.

解决方案Solution

按照以下步骤在运行的群集上安装这些库。Follow the steps below to install these libraries on running clusters.

  1. 在单元格中运行以下命令 %shRun following commands in a %sh cell.

    %sh
    ls -l /usr/bin/java
    ls -l /etc/alternatives/java
    ln -s /usr/lib/jvm/java-8-openjdk-amd64 /usr/lib/jvm/default-java
    R CMD javareconf
    
  2. 安装 rJava 和 RJDBC 包。Install the rJava and RJDBC packages.

    install.packages(c("rJava", "RJDBC"))
    
  3. 验证是否已安装 rJava 包。Verify that the rJava package is installed.

    dyn.load('/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so')
    library(rJava)