如何在Windows机器上安装归档R包?求可行解决方法
sentiment and Rstem R Packages Hey there, sorry to hear you’ve been stuck on this for two hours—let’s break down the most reliable fixes to get these archived packages installed smoothly.
Step 1: Sort Out System Dependencies First
The Rstem package depends on the Snowball stemmer library, a system-level tool that’s required for compiling the source code. If this is missing, your installation will fail no matter what. Here’s how to install it for your operating system:
- Ubuntu/Debian: Open your terminal and run
sudo apt-get install libstemmer-dev - CentOS/RHEL: Use
sudo yum install stemmer-devel(orsudo dnf install stemmer-develfor newer releases) - macOS: Use Homebrew with
brew install libstemmer
Step 2: Install Rstem First (It’s a Hard Dependency for sentiment)
These packages have a strict order—sentiment won’t install unless Rstem is already on your system. Try these methods in your R console:
Option A: Install Directly from the CRAN Archive URL
Run these lines one at a time:
# Install Rstem first install.packages("https://cran.r-project.org/src/contrib/Archive/Rstem/Rstem_0.4-1.tar.gz", repos = NULL, type = "source") # Then install sentiment install.packages("https://cran.r-project.org/src/contrib/Archive/sentiment/sentiment_0.2-1.tar.gz", repos = NULL, type = "source")
Option B: Manual Local Installation (If URL Install Fails)
- Download both tar.gz files from the archive pages to your computer:
Rstem_0.4-1.tar.gzsentiment_0.2-1.tar.gz
- In R, set your working directory to where you saved the files (use
setwd("/path/to/your/saved/files")), then run:
install.packages("./Rstem_0.4-1.tar.gz", repos = NULL, type = "source") install.packages("./sentiment_0.2-1.tar.gz", repos = NULL, type = "source")
Step 3: Fix R Version Compatibility (If You Still Hit Errors)
These packages are extremely old (last updated in 2014), so they might not work with modern R versions (4.0+). If you get compilation errors related to R API changes, try these workarounds:
- Use
renvto create a project-specific environment with an older R version (e.g., 3.1.3, which was current when these packages were released). - Use Docker to spin up a container with an old R image—this keeps your main R setup untouched:
Then run the installation commands inside the container.docker run -it rocker/r-ver:3.1.3
Alternative: Switch to Maintained Sentiment Analysis Packages
If you can’t get these old packages working, consider using modern, actively maintained alternatives that do the same job better:
sentimentr: A robust, up-to-date package for fine-grained sentiment analysistidytext: Integrates seamlessly with the tidyverse for text analysis taskstextdata: Provides access to pre-trained sentiment lexicons
内容的提问来源于stack exchange,提问作者Lucinho91

