Description Usage Arguments Details Value Note Author(s) References See Also Examples
Calls interpret
on each individual dose string, to
extract structured information such as quantity, frequency and units.
1 2 3 4  doseconvert(text, textid = seq_along(text), simplify = TRUE,
singlewords = NULL, multiwords = NULL, patterns = NULL,
maxifchoice = TRUE, usebuiltinlookups = TRUE,
customlookups = NULL, cores = 1, noisy = FALSE)

text 
Dosage strings to be interpreted. 
textid 
Optional vector of text or numeric identifiers for the dosage strings. 
simplify 
FALSE if multiple periods with different doses should be returned as separate doses; TRUE if they should be combined into a single dose (default), thus returning one row per original dosage text. 
singlewords 
A 
multiwords 
A 
patterns 
A 
maxifchoice 
Whether to return the maximum dose if there is a choice of dose (e.g. 1 or 2 tablets daily). If FALSE, the average is returned. 
usebuiltinlookups 
Whether to use the lookup table of exact dose strings and their conversion included in the package. 
customlookups 
A 
cores 
Number of cores to use, for multiprocessor machines running R on Linux. The 'parallel' package must be loaded in order to use more than one core. 
noisy 
TRUE or FALSE  whether to print debug information to console. 
This function calls interpret
repeatedly to analyse
individual dosage texts. First it compiles a list of unique dosage texts
to be analysed, so that each is interpreted only once.
If usebuiltinlookups = TRUE
and a text is found in the lookups table, or if it is in the customlookups
table, the preanalysed output is
returned, otherwise the interpret
function is called to
analyse the text.
Data frame with the following columns:

numeric or character; text identifier 

numeric; if 

numeric; dose quantity 

numeric; dose units 

character; dose units 

numeric; dose frequency per time period 

numeric; total dose per time period 

factor with 3 levels: max, average, exact 

numeric; time interval in number of days 

factor with 3 levels: first, second, nochange, combined.
If doses for different time periods combined using 

factor with 3 levels: choice, asneeded, nochoice 

numeric; duration of prescription 

numeric; calculated daily dose (0 = missing) 
If simplify
= TRUE, the row.names are the ids
if supplied, or equal to the row numbers otherwise.
If simplify
= FALSE, the row.names are ids
.X where X (=1, 2, 3 etc.) is the order of the partial
dose if ids
are supplied, or equal to the row numbers otherwise.
Converted from the original Visual Basic algorithm.
Anoop Shah
Shah AD, Martinez C. An algorithm to derive a numerical daily dose from unstructured text dosage instructions. Pharmacoepidemiol Drug Saf 2006; 15(3): 161166. doi: 10.1002/pds.1151 http://onlinelibrary.wiley.com/doi/10.1002/pds.1151/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31  # Using default dictionaries (loaded each time by function)
doseconvert(c('2 tab twice daily',
'one daily for 1 week then two daily'),
textid = 1:2, simplify = FALSE)
doseconvert('one daily for 1 week then two daily',
textid = 2, simplify = TRUE)
# Timing test
system.time(doseconvert(text = '2 tablets daily', textid = 3))
# Preloading dictionaries for faster analysis
# This is particularly useful when running in server mode for ondemand
# dosage text conversion
data(singlewords)
the_singlewords < as.drugdose_singlewords(singlewords)
data(multiwords)
the_multiwords < as.drugdose_multiwords(multiwords)
data(patterns)
the_patterns < as.drugdose_patterns(patterns)
data(lookups)
the_lookups < as.drugdose_lookups(lookups)
# Write a function to use preloaded dictionaries
doseconvert_fast < function(text, textid){
doseconvert(text = text, textid = textid, simplify = TRUE,
singlewords = the_singlewords, multiwords = the_multiwords,
patterns = the_patterns, usebuiltinlookups = FALSE,
customlookups = the_lookups, cores = 1)
}
system.time(doseconvert_fast(text = '2 tablets daily', textid = 3))

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.