Implemented a switch (arg) that allows new behaviour (optional) ...

without breaking code that relies on old behaviour (default).
master
Taha Ahmed 13 years ago
parent ca87357da3
commit 7d6044143b

@ -1,16 +1,21 @@
ProvideSampleId <- function (pathexpfile) {
ProvideSampleId <- function (pathexpfile, implementation = "filename") {
# Returns a "unique" sample ID when supplied
# with a path to an experimental file.
## Note: the sample ID must derive directly from the file or path.
# 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.
## Note to myself: the sample ID must derive directly from the file or path.
if (implementation == "dirname") {
# basename(dirname()) returns the name of the lowest sub-directory
# split()[[1]][2] splits the dirname at the hyphen and returns the sampleid
sampleid <- strsplit(x = basename(dirname(pathexpfile)),
split = "-")[[1]][2]
# # basename() returns the filename sans path
# # sub() returns the filename sans extension
# sampleid <- sub("\\.[\\w]+$", "", basename(pathexpfile), perl = TRUE)
} else {
# basename() returns the filename sans path
# sub() returns the filename sans extension
sampleid <- sub("\\.[\\w]+$", "", basename(pathexpfile), perl = TRUE)
}
#### The code below is the old ProvideSampleId() function
# ### OBS! Only very rudimentary error-checking.

@ -1,6 +1,8 @@
The following function, \Rfun{ProvideSampleId()}, strives to supply a unique sample ID from any path supplied to it. Of course, a certain structure on the part of the path and filename are assumed, namely:
\begin{itemize}
\item That the filename (not including the extension) consists of three alphanumeric strings separated by hyphens.
\item That\ldots
\end{itemize}
The aim with \Rfun{ProvideSampleId()} is to supply a unique sample ID from any full path supplied to it.
The function solves this using two approaches:
\begin{enumerate}
\item using only the filename,
\item using only the name of the subdirectory in question.
\end{enumerate}

Loading…
Cancel
Save