From 6469feb7bef67cddc2be97fa45f957bd50724c53 Mon Sep 17 00:00:00 2001 From: Taha Ahmed Date: Tue, 8 Mar 2011 18:05:24 +0100 Subject: [PATCH] Created the new function ProvideSampleId(). --- common.R | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) mode change 100755 => 100644 common.R diff --git a/common.R b/common.R old mode 100755 new mode 100644 index 7414748..1f1bf96 --- a/common.R +++ b/common.R @@ -3,6 +3,7 @@ # Taha Ahmed, Jan 2011 # CONTENTS +# >>>> ProvideSampleId # >>>> ConvertRefPot # >>>> Celsius2Kelvin # >>>> Kelvin2Celsius @@ -12,6 +13,34 @@ +################################################## +################ ProvideSampleId ################# +################################################## +ProvideSampleId <- function (fullpathwithfilename) { + ### OBS! Only very rudimentary error-checking. + ### If the filename is formatted as \w*-\w*-\w*, we use the middle segment, + ### otherwise we use the whole string (excluding the extension) + # Extract the name of the parent directory of the datafilename argument + substrateid <- basename(dirname(fullpathwithfilename)) + # Extract the name of the method from the filename-part + # First split the filename over all hyphens + nameparts <- strsplit(basename(fullpathwithfilename), "-")[[1]] + # If the number of nameparts exceed 3, save the whole filename as methodid, otherwise use the middle part + if (length(nameparts) > 3) { + # We need to lose the file extension from the last namepart + nameparts[length(nameparts)] <- strsplit(nameparts[length(nameparts)], "\\.")[[1]][1] + methodid <- paste(nameparts, collapse = "-") + } else { + methodid <- nameparts[2] + } + # Make an informative sampleid + sampleid <- paste(substrateid, methodid, sep = "-") + # + return(sampleid) +} + + + ################################################## ################# ConvertRefPot ################## ##################################################