![RStudio:上傳 Excel 檔案時遇到問題。 「沒有名為『pkgconfig』的軟體包](https://rvso.com/image/1605167/RStudio%EF%BC%9A%E4%B8%8A%E5%82%B3%20Excel%20%E6%AA%94%E6%A1%88%E6%99%82%E9%81%87%E5%88%B0%E5%95%8F%E9%A1%8C%E3%80%82%20%E3%80%8C%E6%B2%92%E6%9C%89%E5%90%8D%E7%82%BA%E3%80%8Epkgconfig%E3%80%8F%E7%9A%84%E8%BB%9F%E9%AB%94%E5%8C%85.png)
我能夠將 Excel 電子表格匯入 RStudio 並在工作時處理它,因此我決定透過電子郵件向自己發送相同的電子表格並在家中處理它。當我下載excel檔案並嘗試將其匯入家中的RStudio環境時,我收到以下錯誤訊息:
“這是一個有效的 Excel 檔案嗎?沒有一個名為‘pkgconfig’的套件”
我已經嘗試全新安裝 R 和 RStudio,只需安裝 pkgconfig,並更新盡可能多的軟體包,但我仍然收到此錯誤訊息。
我還嘗試將 Excel 檔案轉換為 .csv,但收到類似的錯誤訊息「沒有名為『pkgconfig』的套件」。
在嘗試這段程式碼時:
庫(readxl)
FinancialSpreadsheet <- read_excel("FinancialSpreadsheet.xlsx")
我收到:
loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) 中發生錯誤:沒有名為「pkgconfig」的套件
我覺得我可能忽略了一些明顯的事情,因為我對這種語言和軟體相當陌生。感謝您的任何幫助。
答案1
這實際上只是回答了我的問題!顯然,R 將包存放在與提取這些包的位置不同的位置。
答案2
- 部分問題是 pkgconfig 未安裝
- 另外,在 Windows 中,當前目錄經常發生變化,因此永遠不應該依賴它。您可以將 if 語句與 file.exists(fileNamePath) 之類的內容結合使用來執行測試。
- read_excel需要設定參數path應該指向file-name-path
例子
....
#install up required packages
install.packages("pkgconfig")
install.packages("Rcpp")
install.packages("readxl")
#load up required packages
library(pkgconfig)
library(Rcpp)
library(readxl)
#load up an excel spreadsheet into a variable object called datasets
filePath <- "C:/.../extdata/evaluation/"
fileName <- 'GPW Detailed Tables March 2019 - STP.xlsx'
fileNamePath <- paste0(filePath, fileName)
#TEST FILE is where you think it is
file.exists(fileNamePath)
#read_excel(datasets)
#FinancialSpreadsheet <- read_excel("FinancialSpreadsheet.xlsx")
#return data into a tibble Data Frame
datasets <- read_xlsx(path = fileNamePath,
sheet = '1a',
range = "D18:L26")
#return data result to the terminal screen
read_excel(path = fileNamePath,
sheet = '1a',
range = "D18:L26")
....
在我的盒子上使用電子表格的 O/P 範例
....
> fileNamePath <- paste0(filePath, fileName)
> file.exists(fileNamePath)
[1] TRUE
> datasets <- read_xlsx(path = fileNamePath,
+ sheet = '1a',
+ range = "D18:L26")
New names:
* `` -> ...2
* `` -> ...3
>
> read_excel(path = fileNamePath,
+ sheet = '1a',
+ range = "D18:L26")
New names:
* `` -> ...2
* `` -> ...3
# A tibble: 8 x 9
`Lancashire and South C~ ...2 ...3 `1263` `689` `255` `8` `185` `145`
<chr> <lgl> <chr> <dbl> <dbl> <dbl> <chr> <dbl> <dbl>
1 00Q NA NHS Blackburn wit~ 110 65 19 - 11 16
2 00R NA NHS Blackpool CCG 97 56 16 1 17 8
3 00X NA NHS Chorley and S~ 125 59 33 1 18 14
4 01A NA NHS East Lancashi~ 313 153 61 2 41 63
5 01E NA NHS Greater Prest~ 148 68 35 2 32 13
6 01K NA NHS Morecambe Bay~ 279 176 60 2 34 8
7 02G NA NHS West Lancashi~ 72 42 10 - 8 13
8 02M NA NHS Fylde and Wyr~ 130 71 23 - 24 13
>
....