[英]How to get a path string from R that I can paste immediately into Windows
假设我有一个 Windows 路径: "R:\\data\\state-capitals\\final\\"
如果我添加“\\”,我可以使用 R 控制台中的路径(在 Windows 系统上)。
mypath = "R:\\data\\state-capitals\\final\\";
如果我有 R 控制台表单
mypath = "R:/data/state-capitals/final/";
normalizePath(mypath);
# "R:\\data\\state-capitals\\final"
我怎么走另一条路? 我如何让 R 将某些内容打印到我可以复制的屏幕上,单击 Win-R 并粘贴以使用文件资源管理器转到该位置......我希望它在屏幕(以及剪贴板)上打印一些内容。
我知道nchar("\\\\")
是一个,但这不允许我最小化字符串操作......我希望 R 输出如下内容: R:\\data\\state-capitals\\final\\
所以我可以复制/ 粘贴回 Windows 环境。
保留尾部斜杠的解决方案会很好。
基于@Linh,这里有一些功能......
https://gist.github.com/MonteShaffer/8555de33cec2b6ffff81c268bcccc041
# https://stackoverflow.com/questions/64476043/
# https://stackoverflow.com/questions/1189759/
convertDirectoryR.toWin = function(myDir = getwd()) # "R:/data/state-capitals/final/"
{
cat( normalizePath(myDir) );
writeClipboard( normalizePath(myDir) ); # R:\data\state-capitals\final\
}
openDirectoryR.inWin = function(myDir = getwd()) # "R:/data/state-capitals/final/"
{
cmd = paste("explorer", gsub('/', '\\\\', myDir, fixed=TRUE ) );
suppressWarnings( shell( cmd ) ); # R:\data\state-capitals\final\
}
convertDirectoryWin.toR = function(myDir = readClipboard()) # # R:\data\state-capitals\final\
{
gsub('\\', '/', myDir, fixed=TRUE ); # "R:/data/state-capitals/final/"
}
除了粘贴,我怎样才能读入 winDir? 使用convertDirectoryWin.toR
?
我认为你可以使用cat()
mypath = "R:/data/state-capitals/final/"
cat(normalizePath(mypath))
# "R:\data\state-capitals\final\
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.