制作动态网址表列

时间:2019-06-30 04:53:09

标签: r url

我有一个简单的数据表,其中有一列record_id数字。我想添加一个额外的列,以使用URL中的record_id创建一个URL。

我尝试使用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之类的事情,但无法弄清楚=号之后会发生什么。

1 个答案:

答案 0 :(得分:0)

对于处于相同情况的人,

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