2012-08-02 8 views
2

strwrap 함수를 strWrap으로 감싸고 있습니다.이 함수는 클립 보드에서 텍스트를 받아 들일뿐만 아니라 클립 보드에 자동으로 쓰는 것입니다. 이것에서 나는 mac의 시스템 이름이 Darwin이라고 가정하고있다. 이 함수는 윈도우 머신에서 작동한다. (미안하다. 리눅스는이 함수를 사용하는 대부분의 사람들이 어쨌든 리눅스 사용자가되지 못하도록 &을 구현할 수있는 변형이 너무 많다.)클립 보드가 Mac에서 작동하지 않습니다

psych 패키지의 read.clipboard 기능 후에 필자의 기능을 모델링했습니다. 불행히도, 나는 어떤 사람들에게 맥을 가지고 있었고 작동하지 않는 talkstats.com에 그것을 시도해달라고 요청했다. Mac에서도이 작업을 수행하려면 어떻게해야합니까? this SO post에 따르면 내 코드는 Mac 사용자를 위해서도 잘 작동하는 것처럼 보입니다.

예상대로 작동하면 Mac 사용자의 경우 클립 보드에서 읽은 다음 작업이 끝나면 클립 보드에 쓸 수 있어야합니다. 나는 문제

strWrap <- 
function(text = "clipboard", width = 70) { 
    if (text == "clipboard") { 
     if (Sys.info()["sysname"] == "Darwin") {  # 
      text <- paste(pipe("pbpaste"), collapse=" ")# 
     }            # 
     if (Sys.info()["sysname"] == "Windows") { 
      text <- paste(readClipboard(), collapse=" ") 
     } 
    } 
    x <- gsub("\\s+", " ", gsub("\n|\t", " ", text)) 
    x <- strwrap(x, width = width) 
    if (Sys.info()["sysname"] == "Windows") { 
     writeClipboard(x, format = 1) 
    } 
    if (Sys.info()["sysname"] == "Darwin") {   # 
     j <- pipe("pbcopy", "w")      # 
     cat(x, file = j)        # 
     close(j)          # 
    }             # 
    writeLines(x) 
} 

X <- "Two households, both alike in dignity, In fair Verona, where we lay 
our scene, From ancient grudge break to new mutiny, Where civil blood 
makes civil hands unclean. From forth the fatal loins of these two 
foes A pair of star-cross'd lovers take their life; Whose 
misadventured piteous overthrows Do with their death bury their 
parents' strife. The fearful passage of their death-mark'd love, And 
the continuance of their parents' rage, Which, but their children's 
end, nought could remove, Is now the two hours' traffic of our stage; 
The which if you with patient ears attend" 

strWrap(X, 70) 
+0

"죄송합니다."Linux 사용자는 Linux와 관련하여 아무 것도하지 않았습니다. – user1945827

+0

Linux Mint/Ubuntu/Debian의 경우 https://stackoverflow.com/questions/10959521/how-to-write-to-clipboard-on-ubuntu-linux-in-r/44741951#44741951을 참조하십시오. – Deleet

+0

나는 clipr 꾸러미가 OS indep 인 것을 목표로한다고 덧붙였다. 클립 보드에서 /로 복사하는 방법 https://cran.r-project.org/web/packages/clipr/index.html –

답변

3

pipe 연결 객체를 반환 쉽게 이해 끝에 #와 맥 특정 라인을 표시했다. 연결에서 읽어야합니다. 예 :

pcon <- pipe("pbpaste") 
text <- paste(scan(pcon, what="character", quiet=TRUE), collapse=" ") 
close(pcon) 

내 Mac에서 작동합니다.

+0

[이 링크] (http://www.talkstats.com/showthread.php/)를 참조하십시오. p1 = 89986 & viewfull = 1 # post89986)를 사용하여 최종 솔루션을 테스트하십시오. –

관련 문제