在R中访问Powershell安装的驱动器

时间:2014-07-28 19:26:14

标签: r powershell networking nas

所以我有一个Powershell脚本,我想在一个小集群上执行,该脚本的核心是一个R脚本。在Powershell中,我安装了一个驱动器:

New-PSDrive –Name Q: –PSProvider FileSystem –Root \\this-isa-addr01\subdrive

我可以访问Powershell终端中的Q:驱动器。但下一步是运行一个执行以下操作的R脚本:

load("Q:/thisIsAWorkspaceWithABunchOfPrecomputedStuffAndDataInIt")

然而,R无法找到该文件或驱动器。我试过跑

ls("Q:")

无济于事。我收到错误:

Error in as.environment(pos) :  No item called "Q:" on the search list

我也试过

ls("\\\\this-isa-addr01/subdrive")

但这给了我同样的错误。

我是否需要将一些环境变量从powershell传递给R?有没有更好的方法从未安装的驱动器加载数据?

编辑:其他问题,是否可以在R中安装NAS驱动器?这就是我想做的事情,不一定是在Powershell。

编辑:我也尝试过使用-Persist。我找不到参数消息。当我运行Get-Help New-PSDrive时,这是输出,没有提到Persist。

  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.

1 个答案:

答案 0 :(得分:2)

来自Get-Help New-PSDrive

Mapped network drives: You can use the Persist parameter of New-PSDrive to 
create Windows mapped network drives. Unlike temporary Windows PowerShell 
drives, Windows mapped network drives are not session-specific; they are 
saved in Windows and they can be managed by using standard Windows tools, 
such as File Explorer and Net Use. Mapped network drives must have a 
drive-letter name and be connected to a remote file system
location.

如果您要安装驱动器以便其他应用,甚至PowerShell会话都可以看到它,请使用-Persist

注意:如果您遇到Powershell v2,则必须使用net use DRIVELETTER PATH