Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Make a general function with years from a URL

Let’s say I want to make a general function of a URL, for example: https://en.wikipedia.org/wiki/2020 . I want the function to act so read_url(year) generates the desired year. How do I build a general URL for this link?

The function should look like this:

read_url <- function(year){ 

...
}

And below code utilise the function to generate the link:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

read_url(2015)

I assume it has to do with the rvest package.

>Solution :

We could use paste0:

read_url <- function(year){ 
  paste0("https://en.wikipedia.org/wiki/",year)
}

read_url(2015)
[1] "https://en.wikipedia.org/wiki/2015"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading