在RStudio中使用plot()函數時,報錯如下:
Error in gzfile(file, "wb") : cannot open the connectionIn
addition: Warning message:
In gzfile(file, "wb") :
cannot open compressed file 'C:/Users/?????/AppData/Local/Temp/RtmpwD2Fs0/rs-graphics-52dc96e7-e781-462c-bc22-849aea1de068/bbd3eb3a-cd5c-4524-a137-7a1a6ef06a3a.snapshot', probable reason 'Invalid argument'
Graphics error: Plot rendering error
In gzfile(file, "wb") :
cannot open compressed file 'C:/Users/?????/AppData/Local/Temp/RtmpwD2Fs0/rs-graphics-52dc96e7-e781-462c-bc22-849aea1de068/bbd3eb3a-cd5c-4524-a137-7a1a6ef06a3a.snapshot', probable reason 'Invalid argument'
Graphics error: Plot rendering error
原因為路徑中含有中文,即我的用戶名是中文字符。由於更改Windows用戶名非常容易導致系統崩潰,並且一些環境變量路徑也需要更改,所以我准備增加一個英文的用戶。方法如下:
1.設置 -> 賬戶 -> 家庭和其他成員,選擇“將其他人添加到電腦”

2.彈出的對話框中選擇“我沒有這個人的登陸信息”
3.選擇“添加一個沒有Windows賬戶的用戶”
4.設置用戶名,密碼等
5.將用戶類型改為管理員
可以發現C盤Users目錄下增加了一個新的文件夾,即剛剛添加的用戶。打開該文件夾,進入AppData->Local->Temp,復制路徑,添加到系統環境變量Tmp和Temp中。
重新打開RStudio,出現錯誤:Fatal Error: cannot create R_TempDir,將Temp目錄下的文件刪除,使之成為一個空目錄,Rstudio終於可以順利打開,也可以做圖。