<!-- Generated by pkgdown: do not edit by hand --><htmllang="en"><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"><metacharset="utf-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><metaname="viewport"content="width=device-width, initial-scale=1, shrink-to-fit=no"><metaname="description"content="Use this function on e.g. clinical texts from health care records. It returns a list with all antimicrobial drugs, doses and forms of administration found in the texts."><title>Retrieve Antimicrobial Drug Names and Doses from Clinical Text — ab_from_text • AMR (for R)</title><!-- favicons --><linkrel="icon"type="image/png"sizes="16x16"href="../favicon-16x16.png"><linkrel="icon"type="image/png"sizes="32x32"href="../favicon-32x32.png"><linkrel="apple-touch-icon"type="image/png"sizes="180x180"href="../apple-touch-icon.png"><linkrel="apple-touch-icon"type="image/png"sizes="120x120"href="../apple-touch-icon-120x120.png"><linkrel="apple-touch-icon"type="image/png"sizes="76x76"href="../apple-touch-icon-76x76.png"><linkrel="apple-touch-icon"type="image/png"sizes="60x60"href="../apple-touch-icon-60x60.png"><scriptsrc="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><metaname="viewport"content="width=device-width, initial-scale=1, shrink-to-fit=no"><linkhref="../deps/bootstrap-5.3.1/bootstrap.min.css"rel="stylesheet"><scriptsrc="../deps/bootstrap-5.3.1/bootstrap.bundle.min.js"></script><linkhref="../deps/Fira_Code-0.4.7/font.css"rel="stylesheet"><!-- Font Awesome icons --><linkrel="stylesheet"href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css"integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk="crossorigin="anonymous"><linkrel="stylesheet"href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css"integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw="crossorigin="anonymous"><!-- bootstrap-toc --><scriptsrc="https://cdn.jsdelivr.net/gh/afeld/bootstrap-toc@v1.0.1/dist/bootstrap-toc.min.js"integrity="sha256-4veVQbu7//Lk5TSmc7YV48MxtMy98e26cf5MrgZYnwo="crossorigin="anonymous"></script><!-- headroom.js --><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js"integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0="crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js"integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4="crossorigin="anonymous"></script><!-- clipboard.js --><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js"integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI="crossorigin="anonymous"></script><!-- search --><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js"integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A=="crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js"integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg=="crossorigin="anonymous"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js"integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww=="crossorigin="anonymous"></script><!-- pkgdown --><scriptsrc="../pkgdown.js"></script><linkhref="../extra.css"rel="stylesheet"><scriptsrc="../extra.js"></script><metaproperty="og:title"content="Retrieve Antimicrobial Drug Names and Doses from Clinical Text — ab_from_text"><metaproperty="og:description"content="Use this function on e.g. clinical texts from health care records. It returns a list with all antimicrobial drugs, doses and forms of administration found in the texts."><metaproperty="og:image"content="https://msberends.github.io/AMR/logo.svg"><metaname="twitter:card"content="summary_large_image"><metaname="twitter:creator"content="@msberends"><
<p>Use this function on e.g. clinical texts from health care records. It returns a <ahref="https://rdrr.io/r/base/list.html"class="external-link">list</a> with all antimicrobial drugs, doses and forms of administration found in the texts.</p>
<span> type <spanclass="op">=</span><spanclass="fu"><ahref="https://rdrr.io/r/base/c.html"class="external-link">c</a></span><spanclass="op">(</span><spanclass="st">"drug"</span>, <spanclass="st">"dose"</span>, <spanclass="st">"administration"</span><spanclass="op">)</span>,</span>
<span> info <spanclass="op">=</span><spanclass="fu"><ahref="https://rdrr.io/r/base/interactive.html"class="external-link">interactive</a></span><spanclass="op">(</span><spanclass="op">)</span>,</span>
<dd><p>type of property to search for, either <code>"drug"</code>, <code>"dose"</code> or <code>"administration"</code>, see <em>Examples</em></p></dd>
<dt>collapse</dt>
<dd><p>a <ahref="https://rdrr.io/r/base/character.html"class="external-link">character</a> to pass on to <code>paste(, collapse = ...)</code> to only return one <ahref="https://rdrr.io/r/base/character.html"class="external-link">character</a> per element of <code>text</code>, see <em>Examples</em></p></dd>
<dd><p>if <code>type = "drug"</code>: a column name of the <ahref="antibiotics.html">antibiotics</a> data set to translate the antibiotic abbreviations to, using <code><ahref="ab_property.html">ab_property()</a></code>. The default is <code>FALSE</code>. Using <code>TRUE</code> is equal to using "name".</p></dd>
<dd><p>a <ahref="https://rdrr.io/r/base/logical.html"class="external-link">logical</a> to indicate whether the input must be extensively searched for misspelling and other faulty input values. Setting this to <code>TRUE</code> will take considerably more time than when using <code>FALSE</code>. At default, it will turn <code>TRUE</code> when all input elements contain a maximum of three words.</p></dd>
<dd><p>a <ahref="https://rdrr.io/r/base/logical.html"class="external-link">logical</a> to indicate whether a progress bar should be printed - the default is <code>TRUE</code> only in interactive mode</p></dd>
<p>A <ahref="https://rdrr.io/r/base/list.html"class="external-link">list</a>, or a <ahref="https://rdrr.io/r/base/character.html"class="external-link">character</a> if <code>collapse</code> is not <code>NULL</code></p>
<p>This function is also internally used by <code><ahref="as.ab.html">as.ab()</a></code>, although it then only searches for the first drug name and will throw a note if more drug names could have been returned. Note: the <code><ahref="as.ab.html">as.ab()</a></code> function may use very long regular expression to match brand names of antimicrobial drugs. This may fail on some systems.</p><divclass="section">
<p>At default, the function will search for antimicrobial drug names. All text elements will be searched for official names, ATC codes and brand names. As it uses <code><ahref="as.ab.html">as.ab()</a></code> internally, it will correct for misspelling.</p>
<p>With <code>type = "dose"</code> (or similar, like "dosing", "doses"), all text elements will be searched for <ahref="https://rdrr.io/r/base/numeric.html"class="external-link">numeric</a> values that are higher than 100 and do not resemble years. The output will be <ahref="https://rdrr.io/r/base/numeric.html"class="external-link">numeric</a>. It supports any unit (g, mg, IE, etc.) and multiple values in one clinical text, see <em>Examples</em>.</p>
<p>With <code>type = "administration"</code> (or abbreviations, like "admin", "adm"), all text elements will be searched for a form of drug administration. It supports the following forms (including common abbreviations): buccal, implant, inhalation, instillation, intravenous, nasal, oral, parenteral, rectal, sublingual, transdermal and vaginal. Abbreviations for oral (such as 'po', 'per os') will become "oral", all values for intravenous (such as 'iv', 'intraven') will become "iv". It supports multiple values in one clinical text, see <em>Examples</em>.</p>
<p>Without using <code>collapse</code>, this function will return a <ahref="https://rdrr.io/r/base/list.html"class="external-link">list</a>. This can be convenient to use e.g. inside a <code><ahref="https://dplyr.tidyverse.org/reference/mutate.html"class="external-link">mutate()</a></code>):<br><code>df %>% mutate(abx = ab_from_text(clinical_text))</code></p>
<p>The returned AB codes can be transformed to official names, groups, etc. with all <code><ahref="ab_property.html">ab_*</a></code> functions such as <code><ahref="ab_property.html">ab_name()</a></code> and <code><ahref="ab_property.html">ab_group()</a></code>, or by using the <code>translate_ab</code> argument.</p>
<p>With using <code>collapse</code>, this function will return a <ahref="https://rdrr.io/r/base/character.html"class="external-link">character</a>:<br><code>df %>% mutate(abx = ab_from_text(clinical_text, collapse = "|"))</code></p>
<divclass="sourceCode"><preclass="sourceCode r"><code><spanclass="r-in"><span><spanclass="co"># mind the bad spelling of amoxicillin in this line,</span></span></span>
<spanclass="r-in"><span><spanclass="fu">ab_from_text</span><spanclass="op">(</span><spanclass="st">"500 mg amoxi po and 400mg cipro iv"</span><spanclass="op">)</span></span></span>
<spanclass="r-in"><span><spanclass="fu">ab_from_text</span><spanclass="op">(</span><spanclass="st">"500 mg amoxi po and 400mg cipro iv"</span>, type <spanclass="op">=</span><spanclass="st">"dose"</span><spanclass="op">)</span></span></span>
<spanclass="r-in"><span><spanclass="fu">ab_from_text</span><spanclass="op">(</span><spanclass="st">"500 mg amoxi po and 400mg cipro iv"</span>, type <spanclass="op">=</span><spanclass="st">"admin"</span><spanclass="op">)</span></span></span>
<spanclass="r-in"><span><spanclass="co"># if you want to know which antibiotic groups were administered, do e.g.:</span></span></span>
<spanclass="r-in"><span><spanclass="va">abx</span><spanclass="op"><-</span><spanclass="fu">ab_from_text</span><spanclass="op">(</span><spanclass="st">"500 mg amoxi po and 400mg cipro iv"</span><spanclass="op">)</span></span></span>
<spanclass="r-in"><span> abx_doses <spanclass="op">=</span><spanclass="fu">ab_from_text</span><spanclass="op">(</span><spanclass="va">clinical_text</span>, type <spanclass="op">=</span><spanclass="st">"doses"</span><spanclass="op">)</span>,</span></span>
<spanclass="r-in"><span> abx_admin <spanclass="op">=</span><spanclass="fu">ab_from_text</span><spanclass="op">(</span><spanclass="va">clinical_text</span>, type <spanclass="op">=</span><spanclass="st">"admin"</span><spanclass="op">)</span>,</span></span>
<p></p><p><code>AMR</code> (for R). Free and open-source, licenced under the <atarget="_blank"href="https://github.com/msberends/AMR/blob/main/LICENSE"class="external-link">GNU General Public License version 2.0 (GPL-2)</a>.<br>Developed at the <atarget="_blank"href="https://www.rug.nl"class="external-link">University of Groningen</a> and <atarget="_blank"href="https://www.umcg.nl"class="external-link">University Medical Center Groningen</a> in The Netherlands.</p>