Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrap long url line in R markdown

I've read the various posts on this, but I still haven't found a solution. Here's some example code:

library(dplyr)
library(lubridate)

urlfile<-'https://raw.githubusercontent.com/blakeobeans/Predicting-Service-Calls/master/Data/nc.csv'
dates<-read.csv(urlfile, header=FALSE)
dates$V1 <- mdy(dates$V1)
dates <- dates %>%
    rename("data.time" = V1) %>%
    filter("2017-10-01" >= data.time & data.time >= "2017-06-01") %>%
    group_by(data.time) %>%
    summarise(n = n())

When I output to the pdf...

enter image description here

The same thing happens if I have notes in the code running out of the grey bar.

I've tried using the following line of code at the beginning:

knitr::opts_chunk$set(tidy.opts=list(width.cutoff=60),tidy=TRUE)

But that doesn't help.

like image 340
Blake Shurtz Avatar asked Oct 04 '18 06:10

Blake Shurtz


Video Answer


1 Answers

I had a similar problem when putting package on CRAN (they give a note if Rd file line exceeds 90 characters (NOTE: lines wider than 90 characters)). One of the arguments to my function was url to a github dataset. Solution was to split url into separate arguments. For example:

urlRemote  <- "https://raw.githubusercontent.com/"
pathGithub <- "blakeobeans/Predicting-Service-Calls/master/Data/"
fileName   <- "nc.csv"

And you can use it in your code like this:

paste0(urlRemote, pathGithub, fileName) %>%
    read.csv(header = FALSE)

This solution has an advantage when you want to use multiple files from the same repository as you can use paste0(urlRemote, pathGithub, fileName1), paste0(urlRemote, pathGithub, fileName2), etc.

like image 188
pogibas Avatar answered Oct 11 '22 20:10

pogibas