Checking if an r package is currently attached
<p>I am having trouble with my workflow because I am sourcing multiple scripts in rmarkdown, some of which require the package <code>dplyr</code> and some of which use <code>plyr</code>. </p>

<p>The problem is that the <code>rename</code> function exists in both packages and if <code>dplyr</code> is currently attached the <code>rename</code> function in <code>plyr</code> won't work.</p>

<p>How do I include in my scripts a function that checks if <code>dplyr</code> is attached, and, if it is, detach it? </p>

<p>I know how to detach packages via <code>detach("package:dplyr", unload = TRUE)</code>. What I don't know is how to check if a package is attached or not. </p>