Make data path and file name variable
This commit is contained in:
25
.Rproj.user/9E972B4F/sources/per/t/9E617014
Normal file
25
.Rproj.user/9E972B4F/sources/per/t/9E617014
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"id": "9E617014",
|
||||
"path": "D:/OpusData/OpusData.R",
|
||||
"project_path": "OpusData.R",
|
||||
"type": "r_source",
|
||||
"hash": "1542888404",
|
||||
"contents": "",
|
||||
"dirty": false,
|
||||
"created": 1611062270843.0,
|
||||
"source_on_save": false,
|
||||
"relative_order": 1,
|
||||
"properties": {
|
||||
"tempName": "Untitled1",
|
||||
"cursorPosition": "19,0",
|
||||
"scrollLine": "0"
|
||||
},
|
||||
"folds": "",
|
||||
"lastKnownWriteTime": 1611062469,
|
||||
"encoding": "UTF-8",
|
||||
"collab_server": "",
|
||||
"source_window": "",
|
||||
"last_content_update": 1611062469561,
|
||||
"read_only": false,
|
||||
"read_only_alternatives": []
|
||||
}
|
37
.Rproj.user/9E972B4F/sources/per/t/9E617014-contents
Normal file
37
.Rproj.user/9E972B4F/sources/per/t/9E617014-contents
Normal file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env Rscript
|
||||
|
||||
# Package installation, execute once
|
||||
#if (!require("remotes")) install.packages("remotes")
|
||||
#remotes::install_github("philipp-baumann/simplerspec")
|
||||
|
||||
# Attach package to workspace, execute with every new session
|
||||
library("simplerspec")
|
||||
|
||||
# Determine file path
|
||||
path <- paste(getwd(), "\\OPUS\\", sep = "")
|
||||
file_name <- "Rng02_Rng2630_01.0"
|
||||
file_path <- paste(path, file_name, sep = "")
|
||||
|
||||
# Convert opus binary file into extractable data
|
||||
data <- read_opus_univ(file_path, extract = "spc",atm_comp_minus4offset = FALSE)
|
||||
# Extract data
|
||||
data_x_values <- data[[file_path]]$wavenumbers
|
||||
data_y_values <- as.numeric(data[[file_path]]$spc[1,])
|
||||
|
||||
# Set working directory to path where the result file should appear
|
||||
setwd(paste(path, "..\\DPT", sep = ""))
|
||||
|
||||
# Convert data into dataframe
|
||||
data <- data.frame(data_x_values, data_y_values, row.names = NULL)
|
||||
|
||||
# Replace last "." with "_", add ".DPT" and create file
|
||||
file_name <- paste(sub(".([^.]*)$", "_\\1", file_name), ".DPT", sep = "")
|
||||
file.create(file_name)
|
||||
|
||||
# Fill file with dataframe
|
||||
write.table(data, file_name, row.names = FALSE, col.names = FALSE, sep=",")
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user