簡體   English   中英

R 文件引用在 readxl::read_excel 的上下文中不起作用 function

[英]R file referencing not working in the context of readxl::read_excel function

我想做的是 go 向上三個文件夾到“New Model Setup”文件夾,在該文件夾中我試圖 go 向下進入“Data Inputs”文件夾並訪問我的 excel 文件。

感興趣的文件位於文件夾“C:/Users/Model Dev/New Model Setup/Data Inputs”中,我已將工作目錄設置為...

getwd()

[1] "C:/Users/Model Dev/New Model Setup/Fiscal_Year/Quarter/Run"

我可以使用 list.files() 的兩種不同方法查看此文件位置

list.files('..\\..\\..\\Data Inputs\\')

[1] “存檔”
[2] 《數據輸入主文件.xlsx》

list.files('../../../Data Inputs/')

[1] “存檔”
[2] 《數據輸入主文件.xlsx》

但是,當我在 read_excel function 中使用相同的結構時,我得到錯誤path不存在。

crop_yield <- readxl::read_excel('..\\..\\..\\Data Inputs\\Data Inputs Master File.xlsx',
                                  sheet = "CropYields")

錯誤: path不存在:'..\..\..\Data Inputs\Data Inputs Master File.xlsx'

crop_yield <- readxl::read_excel('../../../Data Inputs/Data Inputs Master File.xlsx',
                                 sheet = "CropYields")

錯誤: path不存在:'../../../Data Inputs/Data Inputs Master File.xlsx'

這是我的解決方法,但這不是我想要的 go 路線,我更願意將所有這些都放在 function 中。

mainDir <- getwd()
setwd('../../../Data Inputs')
crop_yield <- readxl::read_excel('Data Inputs Master File.xlsx',sheet = "CropYields")
setwd(mainDir)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM