2017-06-14 82 views
0

的情況下在R中表示字符串我已將R與另一個強制使用''的軟件集成,因此我無法在R代碼中使用它們。 我需要像這樣創建一個字符串內部的字符串(因爲html代碼): <h1 style="color: #5e9ca0;"> 但是,此代碼必須在一個更大的字符串內。如何在不使用「」或「'

我試過使用paste0,但我仍然需要使用2種不同類型的表示形式的字符串。除了「」和「'之外,是否還有其他符號可以在R中定義一個字符串?有沒有解決我的問題?

+1

這是因爲你擔心逃脫字符? – hwnd

+0

我需要建立一個這樣的功能: Softwarefunction('Rfunctionthatsendsemails('htmlcodethatuses「」「)' – Bruno

+0

from [this](http://r.789695.n4.nabble.com/how-to-input-a (s)-string-without-quote-td872607.html)dred:f = function(a){s = substitute(a) as.character(s) } – Bea

回答

2

不知道在其他地方找到答案的政策(不是SO),但this似乎有伎倆。

f = function(a) { 
     s = substitute(a) 
     as.character(s) 
} 

paste(f(a=this), f(a=is), f(a=my), f(a=string)) 
> [1] "this is my string" 

,或者如果您不想在行情周圍的字符串,比使用:

noquote(paste(f(a=this), f(a=is), f(a=my), f(a=string))) 
>[1] this is my string 
+1

這實際上可能工作,因爲它定義了根本不使用「」的字符串。我將嘗試在內部html代碼中使用「」函數與sendemail()函數一起使用。 謝謝你的想法,我會在測試後編輯此評論 – Bruno

相關問題