Quantcast
Viewing all articles
Browse latest Browse all 1015

Stop fiddling around with copied paths in Windows R

By Sascha W.

I work with R on both Mac OS and Windows. On Windows, you get the option to copy the path of a file or folder by holding Shift while right-clicking on the file or folder. As useful as this feature is, it copies paths to your clipboard in Windows format, e.g. “C:UserssomeoneDocumentsRscriptssomeprojectpreparations.R”

That is not very nice to use in R scripts because you would have to replace every single backslash by a slash or a double backslash to use it. In this (also in other ways) very useful post, I found a nice solution for this.

By putting a function definition into your startup file (e.g., .Rprofile), you can simply put
.repath()
into the R console, paste your path and hit Return twice. The “de-windowsified” path is then in your clipboard. Here is the function definition:

.repath
cat(‘Paste windows file path and hit RETURN twice’)
x
xa
writeClipboard(paste(xa, collapse=” “))
cat(‘Here’s your de-windowsified path. (It’s also on the clipboard.)n’, xa, ‘n’)

}

One nice thing about this (you R experts may of course know this) is that the function does not show up in RStudio’s Environment section, because it is hidden by the dot before the name.

Thanks, Tom for this answer.

Related

To leave a comment for the author, please follow the link and comment on their blog: Rcrastinate.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more…


If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook…

…read more

Source:: r-bloggers.com


Viewing all articles
Browse latest Browse all 1015

Trending Articles