diff --git a/DESCRIPTION b/DESCRIPTION index 20f1301..9f42b4f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,10 +1,13 @@ Package: common Type: Package Title: chepec common -Version: 0.0.0.9004 +Version: 0.0.0.9005 Description: Commonly used functions and scripts. Authors@R: person("Taha", "Ahmed", email = "taha@chepec.se", role = c("aut", "cre")) License: GPL-3 LazyData: TRUE -RoxygenNote: 5.0.1 -Imports: xtable +RoxygenNote: 6.0.1 +Imports: + xtable, + utils, + photoec diff --git a/NAMESPACE b/NAMESPACE index 96ce5d1..74a7225 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -23,6 +23,7 @@ export(molarity2mass) export(numbers2words) export(potentials.as.SHE) export(roundup) +export(simpleCap) export(siunitx.uncertainty) export(thth2d) export(trapz) diff --git a/R/AddColumn2Data-nm2eV.R b/R/AddColumn2Data-nm2eV.R new file mode 100644 index 0000000..2ae002b --- /dev/null +++ b/R/AddColumn2Data-nm2eV.R @@ -0,0 +1,29 @@ +#' AddColumnEnergy +#' +#' A poorly documented function. +#' To be honest I don't remember what it's for. Not exported. +#' +#' @param path.to.folder full path to folder containing data files +#' +#' @return Writes to file. +AddColumnEnergy <- function(path.to.folder) { + txt.files <- + list.files(path = path.to.folder, pattern = "\\.txt$", + full.names = TRUE) + # message(txt.files) + for (f in 1:length(txt.files)) { + this.file <- txt.files[f] + # read the file contents into df + this.data <- + utils::read.table(this.file, header = T, + col.names = c("wavelength", "intensity")) + # add energy (eV) as third column + this.data$energy <- photoec::wavelength2energy(this.data$wavelength) + # message(head(this.data)) + utils::write.table(this.data, + file = this.file, + sep = "\t", + col.names = c("#Wave", "#Intensity", "#Energy"), + row.names = FALSE) + } +} diff --git a/R/common.R b/R/common.R index 4415853..dc7d887 100644 --- a/R/common.R +++ b/R/common.R @@ -1,3 +1,19 @@ +#' Capitalise first letter in each word in string +#' +#' Copied verbatim from https://stackoverflow.com/a/6364905 +#' Also see R doc of base::toupper() +#' +#' @param x string of one or more words +#' +#' @return string +#' @export +simpleCap <- function(x) { + s <- strsplit(x, " ")[[1]] + paste(toupper(substring(s, 1, 1)), substring(s, 2), + sep = "", collapse = " ") +} + + #' LoadRData2Variable #' #' This function loads R-data file into a variable instead of into the workspace. diff --git a/man/AVS2SHE.Rd b/man/AVS2SHE.Rd index a4e7b6e..e91ae96 100644 --- a/man/AVS2SHE.Rd +++ b/man/AVS2SHE.Rd @@ -15,4 +15,3 @@ potential in SHE scale (numeric) \description{ Converts from absolute vacuum scale (AVS) to SHE scale } - diff --git a/man/AddColumnEnergy.Rd b/man/AddColumnEnergy.Rd new file mode 100644 index 0000000..f1d7da7 --- /dev/null +++ b/man/AddColumnEnergy.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/AddColumn2Data-nm2eV.R +\name{AddColumnEnergy} +\alias{AddColumnEnergy} +\title{AddColumnEnergy} +\usage{ +AddColumnEnergy(path.to.folder) +} +\arguments{ +\item{path.to.folder}{full path to folder containing data files} +} +\value{ +Writes to file. +} +\description{ +A poorly documented function. +To be honest I don't remember what it's for. Not exported. +} diff --git a/man/Celsius2Kelvin.Rd b/man/Celsius2Kelvin.Rd index e2d4ed9..6f22df1 100644 --- a/man/Celsius2Kelvin.Rd +++ b/man/Celsius2Kelvin.Rd @@ -15,4 +15,3 @@ Kelvin (numeric) \description{ Converts temperature from Celsius to Kelvin. } - diff --git a/man/ConvertRefPot.Rd b/man/ConvertRefPot.Rd index 67690ef..072fdf4 100644 --- a/man/ConvertRefPot.Rd +++ b/man/ConvertRefPot.Rd @@ -19,4 +19,3 @@ potential in output reference scale (numeric) \description{ Convert from one electrochemical scale to another } - diff --git a/man/ConvertRefPotEC.Rd b/man/ConvertRefPotEC.Rd index 525bfcb..40b082e 100644 --- a/man/ConvertRefPotEC.Rd +++ b/man/ConvertRefPotEC.Rd @@ -23,4 +23,3 @@ SHE: standard hydrogen electrode Ag/AgCl: silver silver-chloride electrode (3M KCl) SCE: saturated calomel electrode } - diff --git a/man/ExtractSampleIdString.Rd b/man/ExtractSampleIdString.Rd index f9edc3a..7889b01 100644 --- a/man/ExtractSampleIdString.Rd +++ b/man/ExtractSampleIdString.Rd @@ -16,4 +16,3 @@ sampleid (character string) Extract sampleid from a string by utilising the fact that samepleid's adhere to a defined format. } - diff --git a/man/GenericXtableSetAttributes.Rd b/man/GenericXtableSetAttributes.Rd index 51ac064..6e0743c 100644 --- a/man/GenericXtableSetAttributes.Rd +++ b/man/GenericXtableSetAttributes.Rd @@ -39,4 +39,3 @@ xtabWithAttributes <- GenericXtableSetAttributes(xtobject) xtabWithAttributes <- GenericXtableSetAttributes(xtobject, nxtdigits = c(0, 2, 2, 4)) } } - diff --git a/man/Kelvin2Celsius.Rd b/man/Kelvin2Celsius.Rd index f8c6b48..c28bf99 100644 --- a/man/Kelvin2Celsius.Rd +++ b/man/Kelvin2Celsius.Rd @@ -15,4 +15,3 @@ degrees Celsius (numeric) \description{ Converts from temperature in Kelvin to degrees Celsius } - diff --git a/man/LoadRData2Variable.Rd b/man/LoadRData2Variable.Rd index 7a81920..7d6f7f8 100644 --- a/man/LoadRData2Variable.Rd +++ b/man/LoadRData2Variable.Rd @@ -17,4 +17,3 @@ This function loads R-data file into a variable instead of into the workspace. Works well when the R-data file contains only ONE variable. Not tested for when the R-data file contains more than one variable. } - diff --git a/man/LongtableXtableHeader.Rd b/man/LongtableXtableHeader.Rd index 871a080..7487724 100644 --- a/man/LongtableXtableHeader.Rd +++ b/man/LongtableXtableHeader.Rd @@ -21,4 +21,3 @@ This function creates a longtable header assuming that the LaTeX document will use the booktabs package. This function should not be used together with \code{booktabs = TRUE} } - diff --git a/man/ProvideSampleId.Rd b/man/ProvideSampleId.Rd index cbe9079..d3f3e1a 100644 --- a/man/ProvideSampleId.Rd +++ b/man/ProvideSampleId.Rd @@ -20,4 +20,3 @@ The second arg is optional, defaults to "old" behaviour, but can be set to "dirname" for another behaviour. The second arg was added so as not to break older code. } - diff --git a/man/RefCanonicalName.Rd b/man/RefCanonicalName.Rd index bdd0c3a..e4e2c22 100644 --- a/man/RefCanonicalName.Rd +++ b/man/RefCanonicalName.Rd @@ -22,4 +22,3 @@ by not requiring them to remember a particular label or name for each reference electrode, instead almost any sufficiently distinct label or string will still be correctly identified. } - diff --git a/man/SHE2AVS.Rd b/man/SHE2AVS.Rd index 0aba5c6..b0ebe39 100644 --- a/man/SHE2AVS.Rd +++ b/man/SHE2AVS.Rd @@ -15,4 +15,3 @@ potential in AVS scale (numeric) \description{ Converts from SHE scale to absolute vacuum (AVS) scale } - diff --git a/man/SubfigureGenerator.Rd b/man/SubfigureGenerator.Rd index b1aa2ac..1d59996 100644 --- a/man/SubfigureGenerator.Rd +++ b/man/SubfigureGenerator.Rd @@ -30,4 +30,3 @@ Generate LaTeX subfigure code for a bunch of supplied image paths, subcaptions, label and subfigure layout. Supports splitting the figures over several pages or using landscape layout. } - diff --git a/man/SubstrateHistory.Rd b/man/SubstrateHistory.Rd index e834b09..a70e611 100644 --- a/man/SubstrateHistory.Rd +++ b/man/SubstrateHistory.Rd @@ -17,4 +17,3 @@ a dataframe \description{ Display the history of a substrate (sampleid) } - diff --git a/man/TabularXtableHeader.Rd b/man/TabularXtableHeader.Rd index c13b6ef..ffc1eb7 100644 --- a/man/TabularXtableHeader.Rd +++ b/man/TabularXtableHeader.Rd @@ -17,4 +17,3 @@ character string (with LaTeX escaping) \description{ This function should be used together with \code{booktabs = TRUE}. } - diff --git a/man/as.SHE.Rd b/man/as.SHE.Rd index 67f710a..6fc16c0 100644 --- a/man/as.SHE.Rd +++ b/man/as.SHE.Rd @@ -27,4 +27,3 @@ potential in SHE scale Convert an arbitrary number of potentials against any known electrochemical scale (or the electronic vacuum scale) to potential vs SHE. } - diff --git a/man/as.degrees.Rd b/man/as.degrees.Rd index 800584e..3598457 100644 --- a/man/as.degrees.Rd +++ b/man/as.degrees.Rd @@ -15,4 +15,3 @@ degrees (numeric) \description{ Convert from radians to degrees } - diff --git a/man/as.radians.Rd b/man/as.radians.Rd index 1bade7b..9dcfc9c 100644 --- a/man/as.radians.Rd +++ b/man/as.radians.Rd @@ -15,4 +15,3 @@ radians (numeric) \description{ Convert from degrees to radians } - diff --git a/man/int2padstr.Rd b/man/int2padstr.Rd index f25aa32..e0f6e1c 100644 --- a/man/int2padstr.Rd +++ b/man/int2padstr.Rd @@ -20,4 +20,3 @@ a string or a vector of strings Converts an integer or a vector of integers to a string of fixed length padded with a specified character (e.g., zeroes). } - diff --git a/man/is.wholenumber.Rd b/man/is.wholenumber.Rd index d384c4f..f46bbab 100644 --- a/man/is.wholenumber.Rd +++ b/man/is.wholenumber.Rd @@ -19,4 +19,3 @@ I am not even sure this function is useful any longer. Kept for legacy purposes just in case some old code depends on it. This function was copied from R's documentation (see ?is.integer). } - diff --git a/man/molarity2mass.Rd b/man/molarity2mass.Rd index ae6cf5f..1056604 100644 --- a/man/molarity2mass.Rd +++ b/man/molarity2mass.Rd @@ -21,4 +21,3 @@ You want to prepare a solution of known molarity and volume of a particular substance. This function calculates the required mass to weigh up. } - diff --git a/man/numbers2words.Rd b/man/numbers2words.Rd index 5f41ec8..273457b 100644 --- a/man/numbers2words.Rd +++ b/man/numbers2words.Rd @@ -26,4 +26,3 @@ Original author: John Fox, Department of Sociology, McMaster University, Hamilto http://cran.csiro.au/doc/Rnews/Rnews_2005-1.pdf http://finzi.psych.upenn.edu/R/Rhelp02a/archive/46843.html } - diff --git a/man/potentials.as.SHE.Rd b/man/potentials.as.SHE.Rd index b0e8eed..7af439c 100644 --- a/man/potentials.as.SHE.Rd +++ b/man/potentials.as.SHE.Rd @@ -25,4 +25,3 @@ This function just outputs a tidy dataframe with potential vs SHE for different scales, electrolytes, concentrations, and temperatures. Using data from literature. } - diff --git a/man/roundup.Rd b/man/roundup.Rd index 87233ec..20c29e8 100644 --- a/man/roundup.Rd +++ b/man/roundup.Rd @@ -18,4 +18,3 @@ a number This function rounds UP to the nearest interval specified by "nearest" http://stackoverflow.com/questions/6461209/how-to-round-up-to-the-nearest-10-or-100-or-x } - diff --git a/man/simpleCap.Rd b/man/simpleCap.Rd new file mode 100644 index 0000000..3895166 --- /dev/null +++ b/man/simpleCap.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/common.R +\name{simpleCap} +\alias{simpleCap} +\title{Capitalise first letter in each word in string} +\usage{ +simpleCap(x) +} +\arguments{ +\item{x}{string of one or more words} +} +\value{ +string +} +\description{ +Copied verbatim from https://stackoverflow.com/a/6364905 +Also see R doc of base::toupper() +} diff --git a/man/siunitx.uncertainty.Rd b/man/siunitx.uncertainty.Rd index baab781..74248c2 100644 --- a/man/siunitx.uncertainty.Rd +++ b/man/siunitx.uncertainty.Rd @@ -19,4 +19,3 @@ a string suitable for use with siunitx num{} command \description{ Writing number with exponent (such as scientific notation) with uncertainty using siunitx } - diff --git a/man/thth2d.Rd b/man/thth2d.Rd index 7440f30..dac4fb5 100644 --- a/man/thth2d.Rd +++ b/man/thth2d.Rd @@ -17,4 +17,3 @@ d-spacings (numeric) \description{ This function applies Bragg's law to calculate d-spacings from thth (n = 1) } - diff --git a/man/trapz.Rd b/man/trapz.Rd index 8f2ab9c..c4f2b62 100644 --- a/man/trapz.Rd +++ b/man/trapz.Rd @@ -18,4 +18,3 @@ vector (of length n - 1) Numerically calculate area under an arbitrary curve (defined by x, y coord pairs) using trapezodial integration. See Wikipedia for more info on trapz integration. } - diff --git a/man/wavelength2num.Rd b/man/wavelength2num.Rd index e5236d3..a62d78f 100644 --- a/man/wavelength2num.Rd +++ b/man/wavelength2num.Rd @@ -17,4 +17,3 @@ Converts wavelength (nm) to wavenumber (cm-1) Only valid for absolute wavelengths, NOT delta wavelengths (ranges) http://www.powerstream.com/inverse-cm.htm } - diff --git a/man/wavenum2length.Rd b/man/wavenum2length.Rd index fcab0ea..fd1fd3f 100644 --- a/man/wavenum2length.Rd +++ b/man/wavenum2length.Rd @@ -17,4 +17,3 @@ Converts wavenumber (cm-1) to wavelength (nm) Only valid for absolute wavenumbers, NOT delta wavenumbers (ranges) http://www.powerstream.com/inverse-cm.htm } -