Loading caret namespace invokes random function?
<p>In loading namespace for <code>caret</code> package, I found following situation:</p>

<pre><code># 1.
set.seed(1)
print(rnorm(1))           # -0.6264538

# 2. Restart R session

# 3.
set.seed(1)
loadNamespace('caret')
print(rnorm(1))           # -0.3262334

# 4. Restart R session

# 5.
loadNamespace('caret')
set.seed(1)
loadNamespace('caret')
print(rnorm(1))           # -0.6264538
</code></pre>

<p>This gave me trouble when I write unit-testing codes for some functions in which the <code>caret</code> namespace is loaded. An example is as follows:</p>

<p>File <code>R/abn.R</code>:</p>

<pre><code>abn &lt;- function(){
  requireNamespace('caret')
  round(rnorm(1), 5)
}
</code></pre>

<p>File <code>tests/testthat/test_abn.R</code>:</p>

<pre><code>context("Test abnomality")

test_that("Anomaly situation", {
  requireNamespace('caret') # Without this line, devtools::check() will fail
                            #   abn() not equal to -0.62645.
                            #   1/1 mismatches
                            #   [1] -0.326 - -0.626 == 0.3
  set.seed(1)
  expect_equal(abn(), -0.62645)
})
</code></pre>

<p>You can see my workaround solution.</p>

<p>Do I miss something here? </p>

<p>Is there an authentic way to avoid this situation?</p>

<p>Or, this workaround might help persons in similar trouble.</p>