我有一个向量的链接,与周围的html代码。
mylinks <- structure(list(traits = c("<a href=\"https://pubmed.ncbi.nlm.nih.gov/1234567\" target=\"_blank\">Response to amphetamines</a>",
"<a href=\"https://pubmed.ncbi.nlm.nih.gov/1234567\" target=\"_blank\">Bilirubin levels</a>",
"<a href=\"https://pubmed.ncbi.nlm.nih.gov/1234567\" target=\"_blank\">Macrophage colony stimulating factor levels</a>"
)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-3L))
我想把它们折叠成一个由";“隔开的细胞。但是,当我运行时:
list_collapsed <- paste0(mylinks, collapse = "; ")
打印出来:
list_collapsed
[1] "c(\"<a href=\\\"https://pubmed.ncbi.nlm.nih.gov/1234567\\\" target=\\\"_blank\\\">Response to amphetamines</a>\", \"<a href=\\\"https://pubmed.ncbi.nlm.nih.gov/1234567\\\" target=\\\"_blank\\\">Bilirubin levels</a>\", \"<a href=\\\"https://pubmed.ncbi.nlm.nih.gov/1234567\\\" target=\\\"_blank\\\">Macrophage colony stimulating factor levels</a>\")"
打印出转义字符。如何调整这段代码,使其能够逐字逐句地打印出每个单元格中所说的内容,而不是包含额外的转义字符?ie:
[1] "<a href=\"https://pubmed.ncbi.nlm.nih.gov/1234567\" target=\"_blank\">Response to amphetamines</a>"; "<a href=\"https://pubmed.ncbi.nlm.nih.gov/1234567\" target=\"_blank\">Bilirubin levels</a>"; \"<a href=\"https://pubmed.ncbi.nlm.nih.gov/1234567\" target=\"_blank\">Macrophage colony stimulating factor levels</a>"
发布于 2020-06-04 14:09:36
您需要专门引用列traits
paste0(mylinks$traits, collapse = "; ")
[1] "<a href=\"https://pubmed.ncbi.nlm.nih.gov/1234567\" target=\"_blank\">Response to amphetamines</a>; <a href=\"https://pubmed.ncbi.nlm.nih.gov/1234567\" target=\"_blank\">Bilirubin levels</a>; <a href=\"https://pubmed.ncbi.nlm.nih.gov/1234567\" target=\"_blank\">Macrophage colony stimulating factor levels</a>"
发布于 2020-06-04 13:57:40
怎么样
paste0(print(mylinks), collapse = "; ")
发布于 2020-06-04 20:04:06
带有str_c
的选项
library(stringr)
str_c(mylinks$traits, collapse = "; ")
https://stackoverflow.com/questions/62196437
复制相似问题