I am trying to read a loaded variable within quotations in r.
我试图读取r中引号内的加载变量。
criterion1 <- colnames(Test1[9])
dlgInput(message = "Input Criterion for "criterion1"")$res
This is currently what I was trying but it does not work. I want the input box to have the column name at the specified location. I was wondering if there is any way for r to read and pull from the variable within the quotations.
这是我正在尝试的,但它不起作用。我希望输入框在指定位置具有列名称。我想知道r是否有任何方法可以读取和引用引号中的变量。
I would like the input box to read "Input Criterion for 'contents within criterion1'"
我希望输入框中的内容为“标准1中'内容的输入标准'”
Thanks
1 个解决方案
#1
2
I like these four ways, which produce Input Criterion for 'am'
.
我喜欢这四种方式,它们为'am'产生输入标准。
criterion1 <- colnames(mtcars)[9]
str1 <- paste0("Input Criterion for '", criterion1, "'.")
str2 <- sprintf("Input Criterion for '%s'", criterion1)
str3 <- glue::glue("Input Criterion for '{column_name}'", column_name=criterion1)
str4 <- glue::glue("Input Criterion for '{criterion1}'")
In future posts, consider using a dataset that's easily accessible by everyone, and stripping out things that are an unnecessary to your core question, like the dlgInput()
and the $res
are here (assuming I'm understanding correctly now).
在以后的帖子中,考虑使用每个人都可以轻松访问的数据集,并删除对核心问题不必要的内容,例如dlgInput()和$ res在这里(假设我现在正确理解)。
Original response
either escape the double quote (str1
), or enclose with single quotes (str2
).
要么转义双引号(str1),要么用单引号(str2)括起来。
str1 <- "Input Criterion for \"criterion1\""
str2 <- 'Input Criterion for \"criterion1\"'
result:
> cat(str1)
Input Criterion for "criterion1"
> cat(str2)
Input Criterion for "criterion1"
I'm surprised there's not a duplicate hit on SO for "[r] escape quote"
我很惊讶,因为“[r]逃避报价”而没有重复报道
#1
2
I like these four ways, which produce Input Criterion for 'am'
.
我喜欢这四种方式,它们为'am'产生输入标准。
criterion1 <- colnames(mtcars)[9]
str1 <- paste0("Input Criterion for '", criterion1, "'.")
str2 <- sprintf("Input Criterion for '%s'", criterion1)
str3 <- glue::glue("Input Criterion for '{column_name}'", column_name=criterion1)
str4 <- glue::glue("Input Criterion for '{criterion1}'")
In future posts, consider using a dataset that's easily accessible by everyone, and stripping out things that are an unnecessary to your core question, like the dlgInput()
and the $res
are here (assuming I'm understanding correctly now).
在以后的帖子中,考虑使用每个人都可以轻松访问的数据集,并删除对核心问题不必要的内容,例如dlgInput()和$ res在这里(假设我现在正确理解)。
Original response
either escape the double quote (str1
), or enclose with single quotes (str2
).
要么转义双引号(str1),要么用单引号(str2)括起来。
str1 <- "Input Criterion for \"criterion1\""
str2 <- 'Input Criterion for \"criterion1\"'
result:
> cat(str1)
Input Criterion for "criterion1"
> cat(str2)
Input Criterion for "criterion1"
I'm surprised there's not a duplicate hit on SO for "[r] escape quote"
我很惊讶,因为“[r]逃避报价”而没有重复报道