Windows10下R无法安装GitHub包(非curl问题)求助
Hey there, let’s work through this frustrating issue you’re having with installing GitHub packages like xaringan. The weird ÿþ error and ignored path segment in your output points to an encoding conflict or path handling issue tied to your username containing a space (Yue Hu_local), which often trips up R’s temporary file processes on Windows.
Here are targeted fixes to try, ordered from simplest to more involved:
1. Use a Space-Free Temporary Directory
The temporary path generated during installation includes your username with a space, which is likely causing the encoding glitch. Let’s override the temp directory to one without spaces:
# Create a space-free temp folder if it doesn't exist dir.create("C:/R_Temp", showWarnings = FALSE) # Set R to use this folder for temp files Sys.setenv(TMP = "C:/R_Temp") Sys.setenv(TEMP = "C:/R_Temp") # Try installing xaringan again devtools::install_github('yihui/xaringan')
Make sure your user account has write permissions for C:/R_Temp.
2. Fix Encoding Mismatches
The ÿþ character is a UTF-16 byte order mark (BOM), indicating a conflict between your system locale and R’s encoding settings. Let’s align everything to UTF-8:
- In RStudio, go to Tools > Global Options > Code > Saving and set "Default text encoding" to UTF-8.
- Add these lines to your
.Rprofile(open it withusethis::edit_r_profile()) to enforce UTF-8 locale on startup:Sys.setlocale(category = "LC_ALL", locale = "English_United States.UTF-8") - Restart RStudio completely before attempting the installation again.
3. Install from Source Manually
If the above doesn’t work, bypass devtools’ temp file handling entirely:
- Download the source zip of xaringan directly from its GitHub repo.
- Unzip it to a space-free directory (e.g.,
C:/xaringan_source). - Run this command in R:
install.packages("C:/xaringan_source", repos = NULL, type = "source")
4. Double-Check Rtools Configuration
Even though devtools::has_devel() returns TRUE, confirm Rtools is correctly in your system PATH:
- Run
Sys.getenv("PATH")in R. Look for paths likeC:/Rtools/binandC:/Rtools/mingw_64/binnear the top of the output. - If they’re missing, add them via Windows’ System Properties > Advanced > Environment Variables (edit the
Pathvariable for your user account).
A quick side note: You’re using R 3.4.3, which is quite old. While you mentioned trying different versions, upgrading to the latest stable R version (paired with the matching Rtools release) might resolve underlying encoding bugs that were fixed in newer updates.
内容的提问来源于stack exchange,提问作者sammo3182

