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에서는 현재 디렉터리가 자주 변경되므로 절대 의존해서는 안 됩니다. file.exists(fileNamePath)와 같은 항목과 결합된 if 문을 사용하여 테스트를 수행할 수 있습니다.
- read_excel에서는 매개변수를 설정해야 합니다. 경로는 파일 이름 경로를 가리켜야 합니다.
예
....
#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
>
....