You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac系统下如何删除R中全部已安装包?解决yaml缺失报错

Fixing the yaml Package Error & Deleting All R Packages on Mac

Hey there, let's work through this issue together. First, I want to point out that you might not need to delete all your packages to fix that yaml error—let's start with the simpler solution, then cover the full package removal if you still need it.

Fixing the "no package called ‘yaml’" Error

The error pops up because RStudio relies on the yaml package for R Markdown functionality, and it's either missing or corrupted. Here's how to install it directly (bypassing any RStudio-specific glitches):

  1. Open Terminal on your Mac (find it in Applications > Utilities).
  2. Type R and hit Enter to launch the R command line.
  3. Run this command to install yaml along with all its required dependencies:
    install.packages("yaml", dependencies = TRUE)
    
  4. Once installation finishes, quit R with q() and restart RStudio—your error should disappear.

Deleting All User-Installed R Packages (If You Still Need To)

If you really want to wipe all packages you've installed (leaving R's critical built-in base packages untouched), you have two reliable methods:

Method 1: Delete Packages via R Command Line

This is the safer option because it automatically avoids R's essential base packages:

  1. Launch R via Terminal or RStudio.
  2. Run this code block to identify and remove all non-base packages:
    # Get list of all installed packages
    all_installed <- installed.packages()[, "Package"]
    # Get list of R's built-in base packages (do NOT delete these!)
    base_packages <- rownames(installed.packages(priority = "base"))
    # Filter out base packages to get the ones you can delete
    to_remove <- setdiff(all_installed, base_packages)
    # Batch delete the target packages
    remove.packages(to_remove)
    

Method 2: Delete Packages Directly via Finder

This hands-on approach works great if R isn't launching properly:

  1. Close RStudio and all R processes (check Activity Monitor to ensure no R instances are running in the background).
  2. Open Finder, press Command + Shift + G to open the "Go to Folder" window.
  3. Paste the correct path for your R installation:
    • For default system R: /Library/Frameworks/R.framework/Versions/[Your R Version]/Resources/library (replace [Your R Version] with your installed version, like 4.3.1—check the Versions folder to confirm)
    • For Homebrew-installed R: /usr/local/lib/R/site-library
  4. In the library folder, delete every folder except these built-in base packages: base, datasets, utils, grDevices, graphics, stats, methods
  5. Restart RStudio, and all your user-installed packages will be gone.

Pro Tip Before Deleting

Before wiping everything, save a list of your current packages so you can reinstall them later easily:

write.csv(installed.packages()[, "Package"], "my_r_packages.csv", row.names = FALSE)

内容的提问来源于stack exchange,提问作者company-slave

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 07:33:19