在 R 中的 shell() 内启动 OneDrive 卡住了

Starting OneDrive within shell() in R gets stuck

我最近问了这个问题:Import synced OneDrive files 但没有给出明确的答案,虽然它让我更深入地研究使用 shell() 命令。

我正在尝试执行以下操作:

observe({
    invalidateLater(60*1000, session)
    shell("cd C:/Users/xxx/AppData/Local/Microsoft/OneDrive && onedrive.exe /reset")
    shell("cd C:/Users/xxx/AppData/Local/Microsoft/OneDrive && onedrive.exe")
    list <- list.files(path = "../../folder/folder", pattern = ".xlsx", recursive = T)
    
    ...
})

这背后的想法是强制关闭 OneDrive 并重新启动它以强制进行不需要物理打开文件的新同步。

使用第一个 shell 命令,OneDrive 关闭得非常快。但是,在第二个命令中,我的 R 卡住了。它将向我显示以下消息:

[OneAuth:Error:9zj9x:00000000-0000-0000-0000-000000000000] OneAuth is not configured
[OneAuth:Error:9zj9x:00000000-0000-0000-0000-000000000000] OneAuth is not configured
[OneAuth:Info:9zkae:xxx] Start task AcquireCredentialSilently [0]
[OneAuth:Info:9zkad:xxx] Finish task AcquireCredentialSilently [0]
[OneAuth:Info:9zkae:xxx] Start task AcquireCredentialSilently [1]
[OneAuth:Info:9zkad:xxx] Finish task AcquireCredentialSilently [1]
[OneAuth:Info:9zkae:xxx] Start task AcquireCredentialSilently [2]
[OneAuth:Info:9zkad:xxx] Finish task AcquireCredentialSilently [2]
[OneAuth:Info:9zkae:xxx] Start task AcquireCredentialSilently [3]
[OneAuth:Info:9zkad:xxx] Finish task AcquireCredentialSilently [3]
[OneAuth:Info:9zkae:xxx] Start task AcquireCredentialSilently [4]
[OneAuth:Info:9zkad:xxx] Finish task AcquireCredentialSilently [4]
[OneAuth:Info:9zkae:xxx] Start task AcquireCredentialSilently [5]
[OneAuth:Info:9zkad:xxx] Finish task AcquireCredentialSilently [5]
[OneAuth:Info:9zkae:xxx] Start task AcquireCredentialSilently [6]
[OneAuth:Info:9zkad:xxx] Finish task AcquireCredentialSilently [6]
[OneAuth:Info:9zkae:xxx] Start task AcquireCredentialSilently [7]
[OneAuth:Info:9zkad:xxx] Finish task AcquireCredentialSilently [7]
[OneAuth:Info:9zkae:xxx] Start task AcquireCredentialSilently [8]
[OneAuth:Info:9zkad:xxx] Finish task AcquireCredentialSilently [8]
[OneAuth:Info:9zkae:xxx] Start task AcquireCredentialSilently [9]
[OneAuth:Info:9zkad:xxx] Finish task AcquireCredentialSilently [9]
[OneAuth:Info:9zkae:xxx] Start task AcquireCredentialSilently [10]
[OneAuth:Info:9zkad:xxx] Finish task AcquireCredentialSilently [10]

我可以看到 OneDrive 中的文件正在同步,但即使据说所有文件都已同步,R 进程也不会停止。当我尝试关闭进程时,它告诉我:

Child process not responding. R will terminate it

有什么解决办法吗?我也想知道是什么导致了这个问题。

似乎通过将 wait = F 放入 shell 函数中来回答,如下所示:

shell("cd C:/Users/xxx/AppData/Local/Microsoft/OneDrive && onedrive.exe", wait = F)

这样启动 OneDrive 将是后台进程,而不是启动子进程。如果您想确保其余代码仅在 OneDrive 完全重新同步后运行,您可以使用 Sys.sleep()。此外,请确保您的 invalidateLater 计时器足够大,不会在同步期间重置 OneDrive