Eliminate backslash irritation in R for Windows

At the beginning of my life, I discovered the pain of R and windows on different pages when it hit the separator between directories and subdirectories. Despite the fact that I know about this problem, it still hurts me to manually put a backslash in front of all my backslashes or replace them with all the backslashes.

I like to copy the path name or full file name with any of several applications that I run on my computer (e.g. XYPlorer, Everything by voidtools) and then paste it into Tinn-R. In any case, I can automate the task that I am currently doing manually.

  • Is there a setting in Tinn-R?
  • Is there a parameter in R?
  • Is there an autohotkey script that could do this for me by default?

Background for those who do not know what I'm talking about

Quote from R for the Windows FAQ, Version for R-2.9.2, BD Ripley and DJ Murdoch

Backslashes must be doubled in R character strings; for example, one needs `` D: \ R-2.9.2 \ Library \ xgobi \ Scripts \ xgobi.bat ". You can make life easier for yourself by using slashes as path separators: they work under Windows

+5
source share
9 answers

I wrote an autohotkey script that runs by typing "rfil" - without inverted commas.

:O:rfil:: ;replaces backslashes with forward slashes in a file name that is stored on the clipboard
StringReplace,clipboard,clipboard,\,/,All
send %clipboard%
return

- , , . authotkey script , , script. script .

, , , .

+7
+2

autohotkey, , - RStudio. .

: . , RStudio.

: , - R. , .

GroupAdd, R, RStudio

;replaces backslashes with forward slashes in a file name that is stored on the clipboard
#IfWinActive ahk_group R
   ^v::
      StringReplace,clipboard,clipboard,\,/,All
      send %clipboard%
   return
#IfWinActive
+2

, , , , , "\ t" "\n".

+1

, , R , :

list.files(, full = TRUE) [ ]

file.path() [ ]

..

+1

:

> replace.slash <- function(path.name) gsub("\\\\","/",path.name)
> path.name <- "c:\\tmp\\"
> replace.slash(path.name)
[1] "c:/tmp/"

[]: . .

, .

+1

AutoIt , ( \ /).

Local $text1 = ClipGet()
$text2=StringReplace($text1,"\","/")
ClipPut($text2)
+1

, ( Java)?

file_sep <- function(){
ifelse(.Platform$OS.type == "unix", "/", "//")
}
file_sep()

, . , , , .

0

Extending @Farrel code a little (thanks a lot!), Here is my AutoHotkey script, which will get the full path to the file for any selected file, and then (if desired) will change the slashes for better use in R.

The script also replaces all mapped drives with the full network path. To use this, you need to edit this script to find your specific mapped drives, and then replace these drive letters with the full path.

It took a bit to set up, but it is so useful. I use it 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
0
source

All Articles