Relief from backslash irritation in R for Windows

前端 未结 9 2323
没有蜡笔的小新
没有蜡笔的小新 2021-02-10 10:41

Early in my R life I discovered the pain of R and windows being on different pages when it came to the separator between directories and subdirectories. Eventhough I know about

9条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-10 11:27

    Expanding slightly on @Farrel's code (thanks so much!), here's my AutoHotkey script that will get the full file path of any file I select and then (if desired) swap the slashes for better use in R.

    The script also replaces any mapped drives with the full network path. To use this you'll need to edit this script to look for your particular mapped drives and then replace those drive letters with the full path.

    It took a bit to set up but it's so useful. I use this every day.

    ;If Windows explorer is active...
    #IfWinActive ahk_class CabinetWClass 
    
    ; ALT + F - Get the filepath to the file
    !f::
    SendInput, ^c
    Sleep 100
    Clipboard := Clipboard
    return
    
    ;Check for and replace mapped drive names on the clipboard with full file paths
    If InStr(Clipboard,"X:\",1) {
    Clipboard := "\\SERVER_NAME\g$\" SubStr(Clipboard,4, (StrLen(Clipboard )))
    } else if InStr(Clipboard,"K:\",1) {
    Clipboard := "\\SERVER_NAME\Data\" SubStr(Clipboard,4, (StrLen(Clipboard )))
    } else if InStr(Clipboard,"Q:\",1) {
    Clipboard := "\\SERVER_NAME\Data\" SubStr(Clipboard,4, (StrLen(Clipboard )))
    } else if InStr(Clipboard,"L:\",1) {
    Clipboard := "\\SERVER_NAME\" SubStr(Clipboard,4, (StrLen(Clipboard )))
    } 
    Return
    
    ; ALT + S - Replaces backslashes with forward slashes (helpful for R)
    ; Source: https://stackoverflow.com/questions/1407238/relief-from-backslash-irritation-in-r-for-windows
    !s::
    StringReplace,clipboard,clipboard,\,/,All
    send %clipboard%
    return
    
    ; Scripts below this point will run in any active window
    #IfWinActive
    

提交回复
热议问题