admin管理员组

文章数量:1389754

I'm working on a script that requires me to reference a table of data stored outside of my current R working directory. My working directory and data is all stored within my anization's Sharepoint system, so in order to keep the script usable for other Sharepoint users, I set up my working directory call to refer to the path through active document context setwd(dirname(rstudioapi::getActiveDocumentContext()$path)). To refer to my dataset, I used the ../ notation to move up out of my working directory to the common parent folder between my script file and my dataset file (three levels up). Then I directly reference the filepath to the dataset to call it up. I've done this successfully in other scripts, but when I try it in this script, it throws an error. I don't know where I've gone wrong. I don't think I've hit on the character limit for filepath names, nor do I have unusual characters in the name. Is there a limit to how many levels you can go up or down in R filepaths?

Just to be clear, I know I could put the dataset in my working directory and that calling up the working directory in a non-direct way isn't ideal, but we have a specific file structure for a reason, and I want this to be a sustainable script that doesn't rely on me having a bunch of files in one folder that only I can access. Other people have to be able to run this script besides me.

# Sample Code (with dummy names for privacy reasons)

## Working directory

setwd(dirname(rstudioapi::getActiveDocumentContext()$path)) #sets the working directory as the folder where the script file is stored

# This sets the working directory as: C:/Users/myusername/My Organization/Group-SharePoint Site2 - Channel Name - Folder Name/Data Storage/PROD

## Data

census<-read_csv("../../../Group-Sharepoint Site1 - Documents/General/Public Datasets/State Name/State Name_ACSST5Y2023_S2101_Veteran Status.csv")

# The common parent folder is three levels up from my working directory

## Error

Error: '../../../Group-Sharepoint Dummy Folder - Documents/General/Public Datasets/State Name/State Name_ACSST5Y2023_S2101_Veteran Status.csv' does not exist in current working directory ('C:/Users/myusername/My Organization/Group-SharePoint Site2 - Channel Name - Folder Name/Data Storage/PROD').

本文标签: rReferencing a csv file outside of a working directory in SharepointStack Overflow