Goal
I know this is not the most efficient way to tidy a data set but I have tab delimitated files I am reading in, removing some rows, transposing, and then copying the first row and inserting it every other line. I can't seem to write the file into my directory though.
Reprex
pacman::p_load(
here,
dplyr,
readr
)
path <- here()
# CI <- read_delim("CI.pfl", "\t", escape_double = FALSE,
# col_names = FALSE, trim_ws = TRUE, skip = 3)
data <- data.frame(x1 = 1:5,
x2 = 2:6,
x3 = 3:7)
row.names(data) <- LETTERS[1:5]
data
data2 <- t(data)
data3 = matrix(nrow = ((nrow(data2)-1)*2), ncol = ncol(data2))
j = 2
for (i in 1:((nrow(data2)-1)*2)) {
if((i %% 2) == 0) {
data3[i,] = data2[j,]
j = j +1
} else (data3[i,] = data2[1,])
}
Seismic_Unix_Input <- as.data.frame(data3)
write_csv2(x = Seismic_Unix_Input,file = here() ,na = FALSE, append = TRUE, col_names = FALSE)
When I go to try to write the file, I keep getting this:
Error
Error in open.connection(file, "ab") : cannot open the connection
In addition: Warning messages:
1: In file(path, "") :
'raw = FALSE' but '/Users/wouldntYouLikeToKnow/wouldntYouLikeToKnow/wouldntYouLikeToKnow/Basetest2/500by500modelbasetest2' is not a regular file
2: In open.connection(file, "ab") :
cannot open file '/Users/wouldntYouLikeToKnow/wouldntYouLikeToKnow/wouldntYouLikeToKnow/Basetest2/500by500modelbasetest2': Is a directory
Am I using the write_x functions incorrectly here? Is it an issue with how my data is set up? Thank you in advance for all the help.