Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Placing a string on the clipboard without a newline

Tags:

clipboard

r

I have a custom function which converts a path with backslashes on the clipboard to one with forward slashes and pastes it back onto the clipboard. The trouble is, when it is pasted back, it comes with a newline. I can't seem to find where this newline has come from as it doesn't seem to be a newline character as such:

btf <- function(){
  backstring <- readClipboard()
  forstring <- gsub("\\\\", "/", backstring)
  writeClipboard(forstring)
}

So to use a sample path: C:\path\to\folder
1. copy path
2. run btf() in R
3. paste

The pasted copy now has a newline after it. I'm running R 3.0.1 under Windows 7.
How can I prevent this newline from appearing?

like image 763
sebastian-c Avatar asked Oct 04 '22 19:10

sebastian-c


1 Answers

USE:

btf <- function(){
  backstring <- readClipboard()
  forstring <- gsub("\\\\", "/", backstring)
  writeClipboard(charToRaw(paste0(forstring, ' ')))
}
like image 121
user1609452 Avatar answered Oct 12 '22 11:10

user1609452