I'd like to take a list of
我想列一份清单
Ids <- c("00234nisduf", "928347ksjdfn", "92837sdfjkbnfgh")
Ids
[1] "00234nisduf" "928347ksjdfn" "92837sdfjkbnfgh"
And turn it into a SOQL query:
并将其转换为SOQL查询:
Id_Query <- "'00234nisduf', '928347ksjdfn', '92837sdfjkbnfgh'"
The output I'm looking for: '00234nisduf', '928347ksjdfn', '92837sdfjkbnfgh'
must have single quotes around each Id and a comma after the quotes for each Id.
我正在寻找的输出:'00234nisduf','928347ksjdfn','92837sdfjkbnfgh'必须在每个Id周围加上单引号,并在每个Id的引号后面加逗号。
I've tried paste(Ids, collapse = ",")
and trying to mix with gsub("\\"" "'", Ids)
but no luck so far.
我已经尝试粘贴(Ids,collapse =“,”)并试图与gsub(“\\”“”“”,Ids)混合但到目前为止没有运气。
Thank you in advance!
先谢谢你!
1 个解决方案
#1
1
Define a function that takes a string and a new string, applies sQuote to its second argument, and uses paste to combine the second argument with the first. Call that function using
定义一个接受字符串和新字符串的函数,将sQuote应用于其第二个参数,并使用paste将第二个参数与第一个参数合并。使用调用该函数
Reduce(your_function, Ids)
EDIT:
编辑:
Or, in one line:
或者,在一行中:
Reduce(function(x,y) paste(x, y, sep=","), sQuote(Ids))
#1
1
Define a function that takes a string and a new string, applies sQuote to its second argument, and uses paste to combine the second argument with the first. Call that function using
定义一个接受字符串和新字符串的函数,将sQuote应用于其第二个参数,并使用paste将第二个参数与第一个参数合并。使用调用该函数
Reduce(your_function, Ids)
EDIT:
编辑:
Or, in one line:
或者,在一行中:
Reduce(function(x,y) paste(x, y, sep=","), sQuote(Ids))