R: Better detach package function

<div>detach_package <- function(pkg, character.only = FALSE)</div>
<div>{</div>
<div>    if(!character.only)</div>
<div>    {</div>
<div>        pkg <- deparse(substitute(pkg))</div>
<div>    }</div>
<div>    search_item <- paste("package", pkg, sep = ":")</div>
<div>    while(search_item %in% search())</div>
<div>    {</div>
<div>        detach(search_item, unload = TRUE, character.only = TRUE)</div>
<div>    }</div>
<div>}</div>
<div></div>
<div>

RStudio-icon