首页 > 解决方案 > 制作动态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 的事情,但无法弄清楚 = 符号之后会发生什么。

标签: rurlredcap

解决方案


对于同样情况的人,

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))

推荐阅读