r - 制作动态Url表列
问题描述
我有一个简单的数据表,其中有一列 record_id 数字。我想添加一个额外的列来创建一个 url,其中包含 url 中的 record_id。
我尝试使用 library(urltools) 包,但无法弄清楚如何为特定行传递 record_id。由于要更改的值在 url 内,因此 url 也有点复杂。
https://website/DataEntry/index.php?pid=27716&id=[this is where record_id needs to be]&page=something&event_id=348187&instance=1
我正在考虑做一些类似 mutate 的事情,但无法弄清楚 = 符号之后会发生什么。
解决方案
对于同样情况的人,
library(urltools)
library(dyplr)
library(DT)
gotoredcapurl <- function(x){
url <- "https://website/DataEntry/index.php?pid=27716&id=2&page=something&event_id=348187&instance=1"
url <-param_set(url, key = "id", value = x)
paste0("<a href='",url,"'>","Open in REDCap","</a>")
}
ds <- ds %>%
rowwise() %>% # This was what I needed all along or else you get an error from mutate that the length is too long (e.g., you're returning all numbers instead of one
mutate(link = gotoredcapurl(record_id))
推荐阅读
- c# - Rx 如何从 Observable.FromAsync 抛出异常
- cors - 有没有办法为 AWS Cognito 自定义域禁用 CORS
- windows - PowerShell ISE 中的命令历史记录存储在哪里?
- javascript - 节点将先前的数据更改写入文件
- google-apps-script - 使用 Apps 脚本对 Google 表格中的边框进行条件格式设置
- excel - 如何将数据从 Google Drive 中的 xlsx 文件传输到同一驱动器中的 Google Sheet?
- tensorflow - tf.linalg.eig 操作是如何实现的,为什么它是可微分的?
- django - Rest Framework - Many 2 Many 关系,通过 API 中的模型字段包含
- html - 电子邮件模板 - 内联部分未在 Outlook 中左右完全对齐
- c - sscanf 获取$变量