如何正确从CRAN归档安装已移除的R包frailtySurv
Hi David, let's work through this together—your attempts were close, but there were small missteps causing the issues. Here's how to get frailtySurv installed properly:
Why your previous methods didn't work
- The zip file approach: R expects source packages in
.tar.gzformat, not manually zipped folders. When you extracted the original.tar.gzand re-zipped it, you likely messed up the package directory structure that R uses to recognize and load the package. That's why it said "installed successfully" butlibrary(frailtySurv)failed. - The direct repos URL approach: The
reposparameter needs to point to a valid CRAN repository root (which has a package index file), not the specific subfolder for an archived package. That's why you got the "unable to access index for repository" error.
Method 1: Install directly from the archived URL (recommended)
First, make sure you have the devtools package installed (it simplifies installing packages from URLs):
install.packages("devtools")
Then use devtools::install_url() to install the specific archived version. Replace the path in the quotes with the exact link to the .tar.gz file you want (e.g., version 1.3.7):
devtools::install_url("https://cran.r-project.org/src/contrib/Archive/frailtySurv/frailtySurv_1.3.7.tar.gz")
Method 2: Manual download + local installation
If you prefer not to use devtools, you can do this manually:
- Go to the CRAN archive page for
frailtySurvand download the.tar.gzfile you want (e.g.,frailtySurv_1.3.7.tar.gz) to your computer. - Use
install.packages()with the local file path, making sure to specifytype="source"(since this is a source package):
# Replace the path with where you saved the file on your computer install.packages("~/Downloads/frailtySurv_1.3.7.tar.gz", repos = NULL, type = "source")
Important note for compilation dependencies
Since this is a source package, you'll need compilation tools installed on your system:
- Windows: Install Rtools (make sure it's added to your system PATH during installation).
- Mac: Install Xcode Command Line Tools (run
xcode-select --installin Terminal). - Linux: Install the necessary build-essential packages (e.g.,
sudo apt-get install r-base-devon Debian/Ubuntu).
Once the installation finishes successfully, you should be able to load the package with library(frailtySurv) without issues.
备注:内容来源于stack exchange,提问作者David Zucker

