使用RStudio对pkg包执行R CMD check时遇缺失文件报错求助
Hey there, let's work through this R CMD check issue you're hitting with your package pkg! The missing temp folder (RtmpQLnSjE) in your AppData/Temp directory is likely a glitch in how R's temporary environment is set up during the check—since your Rmd runs fine manually, the problem is specific to the check's isolated build process.
1. Refresh R's temp directory
R usually manages temp folders automatically, but sometimes they don't get created properly. Start a fresh RStudio session (close all open instances first), then run this in the console to force R to verify and recreate its temp directory:
tempdir(check = TRUE)
Once that runs, try launching R CMD check again.
2. Use a custom temp directory
If the default AppData temp folder is causing permission or auto-deletion issues, switch to a folder you control:
- Create a new folder like
C:/Custom_R_Temp(make sure it's in a location you have full access to) - Set the temp environment variables in R before running the check:
Sys.setenv(TMP = "C:/Custom_R_Temp", TEMP = "C:/Custom_R_Temp") - Run the check directly from the console instead of using the RStudio GUI button:
This forces the check to use your custom folder, avoiding conflicts with the default temp space.devtools::check()
3. Check permissions for the default temp folder
Windows sometimes restricts access to the AppData/Temp directory for background processes like R CMD check:
- Open File Explorer and navigate to
C:/Users/name/AppData/Local/Temp/ - Right-click the folder > Properties > Security tab
- Make sure your user account has Full control permissions. If not, add them, apply the changes, then restart RStudio and try the check again.
4. Clean your package's build files
Old cached build artifacts might be messing with the check process. Run these commands to wipe them:
devtools::clean_dll() devtools::clean_pkg()
Restart RStudio after this, then try running R CMD check once more.
5. Share your full SessionInfo (if you can)
You mentioned you have a SessionInfo() output—if you can share the full details (like your R version, installed package versions, and Windows OS build), that could help spot compatibility issues that might be triggering the temp folder glitch.
内容的提问来源于stack exchange,提问作者Qaswed

