0

I have a simple data-table that has a column of record_id numbers. I would like to have an additional column added on that creates a url with the record_id within the url.

I tried using the library(urltools) package, but could not figure out how to pass the record_id for specific rows. The url is also a bit complicated by the fact that the value to be changed is within the url.

https://website/DataEntry/index.php?pid=27716&id=[this is where record_id needs to be]&page=something&event_id=348187&instance=1

I was thinking of doing something like mutate, but couldn't figure out what would come after the = sign.

wibeasley
  • 5,000
  • 3
  • 34
  • 62
DocProc
  • 103
  • 7
  • 2
    no need to be fancy; use `paste0`, e.g. `df$urls <- paste0('https://foo.com?pid=1234&id=', df$id, '&page=1')` – alistaire Jun 30 '19 at 05:02
  • unless you've already got a bunch of URLs; then use `httr::parse_url`, modify what you need, and then use `httr::build_url` – alistaire Jun 30 '19 at 05:06

1 Answers1

0

For those in same situation,

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))
wibeasley
  • 5,000
  • 3
  • 34
  • 62
DocProc
  • 103
  • 7