0

I am trying to vectorize this call to source_url, in order to load some functions from GitHub:

library(devtools)
# Find ggnet functions.
fun = c("ggnet.R", "functions.R")
fun = paste0("https://raw.github.com/briatte/ggnet/master/", fun)
# Load ggnet functions.
source_url(fun[1], prompt = FALSE)
source_url(fun[2], prompt = FALSE)

The last two lines should be able to work in a lapply call, but for some reason, this won't work from knitr: to have this code work when I process a Rmd document to HTML, I have to call source_url twice.

The same error shows up with source_url from devtools and with the one from downloader: somehwere in my code, an object of type closure is not subsettable.

I suspect that this has something to do with SHA; any explanation would be most welcome.

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
Fr.
  • 2,865
  • 2
  • 24
  • 44

1 Answers1

1

It has nothing to do with knitr or devtools or vectorization. It is just an error in your(?) code, and it is fairly easy to find it out using traceback().

> library(devtools)
> # Find ggnet functions.
> fun = c("ggnet.R", "functions.R")
> fun = paste0("https://raw.github.com/briatte/ggnet/master/", fun)
> # Load ggnet functions.
> source_url(fun[1], prompt = FALSE)
SHA-1 hash of file is 2c731cbdf4a670170fb5298f7870c93677e95c7b
> source_url(fun[2], prompt = FALSE)
SHA-1 hash of file is d7d466413f9ddddc1d71982dada34e291454efcb
Error in df$Source : object of type 'closure' is not subsettable
> traceback()
7: which(df$Source == x) at file34af6f0b0be5#14
6: who.is.followed.by(df, "JacquesBompard") at file34af6f0b0be5#19
5: eval(expr, envir, enclos)
4: eval(ei, envir)
3: withVisible(eval(ei, envir))
2: source(temp_file, ...)
1: source_url(fun[2], prompt = FALSE)

You used df in the code, and df is a function in the stats package (density of the F distribution). I know you probably mean a data frame, but you did not declare that in the code.

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • Thank you very much for your explanation. I still suck at `traceback()`. May I ask, what is the simplest fix here? Rename all calls to `df` to something else? – Fr. Jun 20 '13 at 13:04
  • @Fr. The fix is to make the code actually work before you `source_url()`, i.e. create a `df`, a list or a data frame or whatever, that has a column or an element `Source`. If `df` is the probability density function of the F distribution, `df$Source` won't work. – Yihui Xie Jun 20 '13 at 22:27