0

I have an absolute URL and a relative URL that I would like to join (like urljoin in Python). For the example of How to join absolute and relative urls?:

url1 <- "http://127.0.0.1/test1/test2/test3/test5.xml"
url2 <- "../../test4/test6.xml"

where url2 is given with reference to the absolute URL url1. How can I get the absolute URL for url2?

Frank
  • 2,386
  • 17
  • 26

2 Answers2

0

I've never seen this done in R before but I do know of file.path

url1 <- "http://127.0.0.1/test1/"
url2 <- "test2/test3/test5.xml"
url3 <- "test4/test6.xml"
file.path(url1, url2)
file.path(url2, url3)

If you need something more precise try playing around with the urltools package https://cran.r-project.org/web/packages/urltools/urltools.pdf

RaphaelS
  • 839
  • 4
  • 14
0

Turns out the getRelativeURL function in the XML package is designed for this.

> library(XML)
> getRelativeURL(url2, url1)
[1] "http://127.0.0.1/test1/test4/test6.xml"
Frank
  • 2,386
  • 17
  • 26