title: Use dynamically loaded dlls from package function in global environment in R
body: <p>I have a package called "aaa" that has a function like:</p>
  
  <pre><code>execute_query = function(arg1,symbol_list){eval(.Call("run_query",arg1),
                                             envir = .GlobalEnv)}
  </code></pre>
  
  <p>Here the run_query part is provided by a dll that has been loaded into the global environment in the functions .onLoad function: </p>
  
  <p><code>eval(dyn.load(file.path(dll_path,"liblib.dll")),envir = .GlobalEnv)</code></p>
  
  <p>This is successful and I get this dll listed when I use the <code>getLoadedDLLs()</code> function.</p>
  
  <p>If I copypaste the function outside of the package it all works as intended.
  However in trying to execute the execute_query from the package I  get the error message:</p>
  
  <pre><code> Error in .Call("run_query", arg1) : 
    "run_query" not resolved from current namespace (aaa) 
  </code></pre>
  
  <p>I guess that eval does not work when it comes to referencing linked dlls. How do I run a dll function from within a package function in the global namespace?</p>
  
  <p>I have already tried to register the package using <code>library.dynam</code> but given the dlls are all part of a large external application and I cannot put it in the package directly this will not work. I am ok with hardcoding a dll path to the package so I would rather a rough solutions like executing everything in the global namespace if that works to solve the problem.</p>