不確定為什么這不起作用, install.packages(new.packages,repos="https://cloud.r-project.org") 但是您的錯誤消息(在評論中)是 Installing package into 'C:/Users/user/AppData/Local/R/win-library/4.2' (as 'lib' is unspecified)Error in contrib.url(repos, "source") : trying to use CRAN without setting a mirror Calls: install.packages -> contrib.url Aborted execution 表示它沒有看到repos。(我懷疑您在使用install.packages(..., repos=)時出現了另一個錯誤,因為您沒有查看.Rout文件,所以沒有看到該錯誤。但我不知道sure.) 如果install.packages(..., repos=)不起作用,您可以使用 options(repos = "https://cloud.r-project.org") 在批處理文件的前面,它應該可以工作。