Reading in csv or xlsx files / folders when using dynamic file path generation (I don’t know if this is the right term)

Im running into an issue with my R script, where read.csv fails to read a csv from a file path. Essentially the goal of my script is to build a file path based on the step variable input. My issue is that it will create the correct file path. But R fails to open the connection. This is the part of the script where it builds the file path:

library(tidyverse)
library(ggplot2)
library(readxl)
# ==================== #
Step <- "pntSetting"
# Step Check
properParam <- c('Cleaning', 100, 150, 175, 200, 225, 'pntSetting', 'Final')
Param <- c('Cleaning', 'pntSetting', 'Final')
if(!tolower(Step) %in% tolower(properParam)) {                                  # If Step does not match anything in properParams regardless of capitalization
  stop(paste0('Step needs to be ', paste(properParam, collapse = ", ")))          # Stop script and print the appropriate options
} else if (!Step %in% properParam) {                                            # If Step does not match anything in properParams regarding capitalization
  Step <- Param[grep(tolower(Step), tolower(Param))]                              # use grep() to replace Step with the appropriate Step with correct capitalization
} else if (is.numeric(Step)) {                                                  # If Step is of numeric data type
    Step <- as.character(Step)                                                    # convert to character data type
}
# ==================== #
colKeep <- c("LongLat_ID", "LAT_GPS", "LONG_GPS", "perflac_all", "strSize", "lc01", "lc02", "lc03", "lc04", "lc05", "lc06", "lc07", "lc08", "lc09")
colRm <- c("LongLat_ID", "LAT_GPS", "LONG_GPS")

# Folder Paths
# Data Dictionaries
paramVers <- list(   'Cleaning' = 0, 
                          '100' = 1, 
                          '150' = 2, 
                          '175' = 3, 
                          '200' = 4, 
                          '225' = 5, 
                   'pntSetting' = 5.5, 
                        'Final' = 6 )
OutSuffix <- list('0'   = "_Cleaning", 
                  '1'   = "_100m", 
                  '2'   = "_150m", 
                  '3'   = "_175m", 
                  '4'   = "_200m", 
                  '5'   = "_225m", 
                  '5.5' = "_pntSeting", 
                  '6'   = "_Final" )
InSuffix <- list(  '0' = "_Cleaning", 
                   '1' = "_100m", 
                   '2' = "_150m", 
                   '3' = "_175m", 
                   '4' = "_200m", 
                   '5' = "_225m", 
                 '5.5' = "_255m", 
                   '6' = "_Final" )
Version <- paramVers[[Step]]
inputsuffix <- InSuffix[[as.character(Version)]]
outputsuffix <- OutSuffix[[as.character(Version)]]

if(Step == 'pntSetting'){                     
  iteration <- paste0("A", (Version - 0.5))   # Using "Version to create the file prefix
} else {
  iteration <- paste0("A", Version)           # Using "Version to create the file prefix
}

# Base file paths
base_path <- file.path("Data", "Analysis")                          # Data/Analysis
folder <- paste0(iteration, inputsuffix)
file_path <- file.path(base_path, folder)                           # Data/Analysis/A?_[inputSuffix]

file_path
dir.exists(file_path)
# file_path <- file.path(base_path, paste0(iteration, inputsuffix))   
repFile_path <- file.path(file_path, "Adjust")                      # Data/Analysis/A?_[inputSuffix]/Adjust
snapVal_path <- file.path(base_path, "FullDat")                     # Data/Analysis/FullDat

# File Paths
# File prior to pntSetting
input_file <- file.path(file_path, paste0(iteration, "_QISBLongLatNA.csv")) # csv with the most up to unsnapped station prior to adjustment
# Adjustment Files
ReplaceMissingCoords <- file.path(repFile_path, "ReplaceMissingCoords.csv") # csv for the unsnapped stations
ReAdjustWrongCoords <- file.path(repFile_path, "ReAdjustCoords.csv")        # csv with readjusted coordinates of already snapped stations
HydroMisMatch <- file.path(repFile_path, "HydroMismatch.csv")               # csv with hydrological mismatched stations. 

# QISB Files
snapVal <- file.path(snapVal_path, paste0(iteration, "_QISB.csv")) # The most recent QISB file
repFile_path
dir.exists(repFile_path)

ReplaceMissCoord <- read.csv(ReplaceMissingCoords)    # Manually Snapped Missing Sample Sites
ReAdjustCoords <- read.csv(ReAdjustWrongCoords)       # Sample Sites with Manually adjusted Coordinates.
pntsRemove <- read.csv(HydroMisMatch)                 # Confirmed Hydrological Mismatched

When I run this part of my script. receive this error:

Error in file(file, “rt”) : cannot open the connection

What I’ve been testing is using “pntSetting” as my “step” parameter, which would give me values of 5.5, _255m, and _pntSetting, for “Version”, “inputsuffix” and “outputsuffix” variables, respectively.

The overall file path looks like this: “Data/Analysis/A5_225m/Adjust”

By recreating different versions of the folder path, I’ve deduced the problem down to my “inputsuffix” variable (“_255m” in file path example). I have successfully been able to have the file read when I manually type in “_255m”, but if I use the inputsuffix variable, it will throw the error. The Version variable does not seem to be a problem, as it works in all cases. I have also checked for any typos, and the folder path is correct. I’ve also tried absolute paths (including and excluding working directory path) to test, and the file reads.

Is anyone familiar with this issue, could it be because of my data dictionaries that I’m using to generate folder paths?

Recognized by R Language Collective

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật