Closed wincowgerDEV closed 11 months ago
Also this from garth for reading labspec text files.
read_labspec <-
function(filename) {
spectra <- read.delim(filename,
encoding = "UTF-8",
header = FALSE)
for (i in 1:(nrow(spectra) - 1)) {
for (j in 1:(ncol(spectra) - 1)) {
wavenumber[j] = spectra[1, j + 1]
intensity[j] = spectra[i + 1, j + 1]
}
data <- data.frame(wavenumber,
intensity)
output[[i]] <- data
write.csv(output[[i]], paste('spectra', i, 'csv', sep = '.'),
row.names = FALSE)
}
}
We have this functionality built in now.
Guidelines
Description
data_files <- list.files("FILE PATH HERE") # Identify file names (the file path should lead to the file that contains your .csv files) data_files # Print file names
This loop will 1) read your .csv files into R as individual data frames, 2)
for(i in 1:length(data_files)) { # Head of for-loop assign(data_files[i], # Read and store data frames read_csv(paste0("FILE PATH HERE/", # Make sure you have a backslash at the very end of the file path (as shown) data_files[i]), skip = 2, col_names = c("wavenumber", "intensity"))) # This "skip" function is set to skip the top 2 lines of the data frame when reading in the .csv and can be adjusted to your data accordingly. The col_names function is set to rename the columns to fit the OpenSpecy format. write_csv(get(data_files[i]), # Write CSV files to a new folder paste0("FILE PATH HERE/", # This file string should lead to the NEW folder you'd like to have the edited .csv files placed into. Again, make sure there is a backslash at the end of the string. data_files[i])) }
Problem
Transform data to csv standard
Proposed Solution
Code in desc
Alternatives Considered
Base