I got this code from my Bachelor-Thesis tutor to round file sizes on my computer with R. It seems to be a problem to use his code (Windows) on my Computer (IOS).
I changed the path to the folder already. setwd does not to work and I guess which is why the folder filenames is empty.
Can someone help me?
Thank you. Below I copied the R-Code
library(data.table)
#Auflösung der Daten anpassen
# 1. Data is located in individual folders, which must be addressed one after the other
path_to_folders <- c("/Users/paul/Desktop/Testdaten")
folder_names <- list.files(path_to_folders)
for(i in 1:length(folder_names)){
tryCatch({
# Access relevant data set
path_to_data <- paste(path_to_folders, "\\", folder_names[i], sep="")
setwd(path_to_data)
filenames <- list.files(path_to_data, pattern =".txt")
for(k in 1:length(filenames)){
spc_txt_file<-filenames[k]
spc_txt_dat<-read.table(spc_txt_file)
spc_txt_dat<-spc_txt_dat[,c(1:3)] # only xyz
spc_txt_dat <- round(spc_txt_dat, 2) # Specifying the decimal place
spc_txt_dat <- unique(spc_txt_dat) # Double selection
spc_txt_name<-substr(spc_txt_file, 1,5)
utils::write.table(spc_txt_dat, file = paste0(path_to_data,'/',spc_txt_name, '_gerundet.txt'),
row.names = F, col.names = F)}
}, error=function(e){cat("ERROR :",conditionMessage(e), "\n")})
}
I think the issue here is with the line that says:
path_to_data <- paste(path_to_folders, "\\", folder_names[i], sep="")
IOS doesn't use backslashes in paths like windows does.
Try changing it to
path_to_data <- paste(path_to_folders, "/", folder_names[i], sep="")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.