title: Accessing a Powershell Mounted Drive in R
body: <p>So I have a Powershell script that I would like to execute on a small cluster and the core of that script is an R script. In Powershell I mount a drive with:</p>
  
  <pre><code>New-PSDrive –Name Q: –PSProvider FileSystem –Root \\this-isa-addr01\subdrive
  </code></pre>
  
  <p>and I can access the Q: drive in the Powershell terminal. But the next step is to run an R script that does the following:</p>
  
  <pre><code>load("Q:/thisIsAWorkspaceWithABunchOfPrecomputedStuffAndDataInIt")
  </code></pre>
  
  <p>However, R can't find the file or for that matter the drive. I tried running </p>
  
  <pre><code>ls("Q:")
  </code></pre>
  
  <p>to no avail. I get the error:</p>
  
  <pre><code>Error in as.environment(pos) :  No item called "Q:" on the search list
  </code></pre>
  
  <p>I also have tried to do</p>
  
  <pre><code>ls("\\\\this-isa-addr01/subdrive")
  </code></pre>
  
  <p>but that gives me the same error.</p>
  
  <p>Do I need to pass some environment variable from powershell to R? Is there a better way to load data from an unmounted drive?</p>
  
  <p><strong>EDIT:</strong> Additional question, is it possible to mount a NAS drive in R? That's really what I want to do it doesn't have to be in Powershell.</p>
  
  <p><strong>EDIT:</strong> I have tried using -Persist as well. I get a cannot find parameter message. When I run Get-Help New-PSDrive this is the output which does not mention Persist.</p>
  
  <pre><code>  DESCRIPTION
    The New-PSDrive cmdlet creates a Windows PowerShell drive that is "mapped" to or associated with a location in a data store, such as a network drive, a directory on the local computer, or a registry key.
  
  You can use the Windows PowerShell drives that you create to access data in the associated data store, just like you would do with any mapped drive. You can change locations into the drive (using "set-location", "cd", or "chdir") and access the contents of the drive (using "get-item", "get-childitem", or "dir").
  
  However, the Windows PowerShell drives are known only to Windows PowerShell. You cannot access them by using Windows Explorer, Windows Management Instrumentation (WMI), Component Object Model (COM), or the Microsoft .NET Framework, or by using tools such as Net Use.
  
  Windows PowerShell drives exist only in the current Windows PowerShell session. To make the drive persistent, you can export the session to which you have added the drive, or you can save a New-PSDrive command in your Windows PowerShell profile.
  
  To delete a drive that was created by New-PSDrive, use the Remove-PSDrive cmdlet.
  </code></pre>