0

I have a lot of CSV that need to be standardized. I created a dictionary for doing so and so far the function that I have looks like this:

inputpath <- ("input")

files<- paste0(inputpath, "/", 
                 list.files(path = inputpath, pattern = '*.gz',
                            full.names = FALSE))

standardizefunctiontofiles = lapply(files, function(x){
    DF <- read_delim(x, delim = "|",  na="")
    names(DF) <- dictionary$final_name[match(names(DF), dictionary$old_name)]
})

Nonetheless, the issue that I have is that when I read the CSV and turn them into a dataframe they lose their path and therefore I can't not write each of them as a CSV that matches the input name. What I would normally do would be:

output_name <- str_replace(x, "input", "output")
write_delim(x, "output_name", delim = "|")

I was thinking that a way of solving this would be to make this step:

DF <- read_delim(x, delim = "|",  na="")

so that the DF gets the name of the path but I haven't find any solution for that.

Any ideas on how to solve this issue for being able to apply a function and writing each of them as a standardized CSV?

4

1 に答える 1