Romi
Romi

Reputation: 31

Can't use igraph within r script, when starting from command line

I have written an R script, which I run from R using the command source("script.r"). It works perfectly.

However, when I try to run the exact same script from command line using either one of the commands: Rcript script.r, R --vanilla < script.r or R CMD BATCH script.r I get the error: "Error in library(igraph): there is no package called 'igraph'"

If I remove the line from the script and run it without the command library(igraph), then I get the error that function graph.frame.data could not be found, which is a function of igraph. The script that runs from the Rstudio, does not contain the line library(igraph) and I don't get such an error.

When trying to inform myself about problems of running igraph from a script I have not found any additional information.

Some more information: I am building a graph from multiple files and then doing calculations using the igraph library on that created graph. This is executed within a loop, that goes through all (specific) directories. Output is written out into a file using cat(..).

Thanks for the help in advance.

Upvotes: 0

Views: 221

Answers (1)

Romi
Romi

Reputation: 31

The igraph library was not installed to the default lib position. Using the command library("igraph", lib.loc="..igraph.location..") solved the issue.

The library was loaded and the execution of the script proceeded without problems.

Upvotes: 0

Related Questions