Added function simpleCap()

master
TA 7 years ago
parent 3f4462aae8
commit a11f59eb22

@ -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

@ -23,6 +23,7 @@ export(molarity2mass)
export(numbers2words)
export(potentials.as.SHE)
export(roundup)
export(simpleCap)
export(siunitx.uncertainty)
export(thth2d)
export(trapz)

@ -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)
}
}

@ -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.

@ -15,4 +15,3 @@ potential in SHE scale (numeric)
\description{
Converts from absolute vacuum scale (AVS) to SHE scale
}

@ -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.
}

@ -15,4 +15,3 @@ Kelvin (numeric)
\description{
Converts temperature from Celsius to Kelvin.
}

@ -19,4 +19,3 @@ potential in output reference scale (numeric)
\description{
Convert from one electrochemical scale to another
}

@ -23,4 +23,3 @@ SHE: standard hydrogen electrode
Ag/AgCl: silver silver-chloride electrode (3M KCl)
SCE: saturated calomel electrode
}

@ -16,4 +16,3 @@ sampleid (character string)
Extract sampleid from a string by utilising the fact that samepleid's
adhere to a defined format.
}

@ -39,4 +39,3 @@ xtabWithAttributes <- GenericXtableSetAttributes(xtobject)
xtabWithAttributes <- GenericXtableSetAttributes(xtobject, nxtdigits = c(0, 2, 2, 4))
}
}

@ -15,4 +15,3 @@ degrees Celsius (numeric)
\description{
Converts from temperature in Kelvin to degrees Celsius
}

@ -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.
}

@ -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}
}

@ -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.
}

@ -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.
}

@ -15,4 +15,3 @@ potential in AVS scale (numeric)
\description{
Converts from SHE scale to absolute vacuum (AVS) scale
}

@ -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.
}

@ -17,4 +17,3 @@ a dataframe
\description{
Display the history of a substrate (sampleid)
}

@ -17,4 +17,3 @@ character string (with LaTeX escaping)
\description{
This function should be used together with \code{booktabs = TRUE}.
}

@ -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.
}

@ -15,4 +15,3 @@ degrees (numeric)
\description{
Convert from radians to degrees
}

@ -15,4 +15,3 @@ radians (numeric)
\description{
Convert from degrees to radians
}

@ -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).
}

@ -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).
}

@ -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.
}

@ -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
}

@ -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.
}

@ -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
}

@ -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()
}

@ -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
}

@ -17,4 +17,3 @@ d-spacings (numeric)
\description{
This function applies Bragg's law to calculate d-spacings from thth (n = 1)
}

@ -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.
}

@ -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
}

@ -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
}

Loading…
Cancel
Save