我有一个简单的数据表,该列具有record_id编号的列。我想在上面添加一个额外的列,该列在URL中使用record_id创建一个URL。
我尝试使用库(urltools(软件包,但无法弄清楚如何通过特定行传递record_id。网址也有些复杂,因为要更改的值在URL之内。
https://website/DataEntry/index.php?pid=27716&id=[this is where record_id needs to be]&page=something&event_id=348187&instance=1
我正在考虑做类似突变的事情,但无法弄清楚=标志后会发生什么。
对于那些处于同一情况的人,
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))