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

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.

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.

Related

How to use VBA to run R script

I'm having trouble running my R script from Excel VBA.
I wanted to create a Button in Excel with a macro that runs an R script but I've tried so many versions and none worked.
My path to R is "C:\Program Files\R\R-4.1.1\bin\Rscript.exe"
The path to my R Script is "\repo\xyz\18320\38293\one\redirected folder\Desktop\test_run\test\Code\sample.R"
How can I create a shell on VBA which actually executes the Script?
Can I maybe execute the script from the command line and then connect the excel macro to the command line? I didn´t manage to find a solution.

r: errors creating package with devtools & roxygen2

I'm writing a package containing several functions to make running and evaluating models more streamlined.
I have a function that I'm going to make the first function within my package detailed with roxygen2 comments, which I can include into this write-up as an edit if necessary, but my issue is more with Package Creation.
I've created a separate .R file for the function and it lives within the R folder in within my package folder. I've run R CMD build pkgname and R CMD INSTALL pkgname successfully.
At the document() stage I run it (from console or whether in my terminal using R -e 'library(devtools);document()', deleting the existing NAMESPACE file first) and I get the following error: Try removing ‘/Library/Frameworks/R.framework/Versions/ 3.5/Resources/library/00LOCK-pkgname.
I've already seen the [issue posted here][1] and haven't had success after deleting the 00LOCK-pkgname folder, for two reasons: when I run document(), even when it throws the above error, it doesn't stop running, it just keeps looping (that happens whether I run this in R or use the Terminal). Additionally, no matter how many times I delete the folder, it keeps re-appearing even though I've stopped running the function.
Any insight into why that error is being thrown and the document() function continually runs in a loop?
Best answer I've found is in this blog post: Hilary Parker R-Package Blog Post
The steps I follow to document and install are as follows:
Within the project that contains my package, open a new R Script and run setwd('..')
Run devtools::document()
Run devtools::install()
This works for me when initially installing my package and also updating it.

how to display r console in matlab

i am running a R script in MATLAB environment using the "system" command as described in:
How to Run a R script from Matlab
my R script takes too long to proceed. when i use the Rstudio itself, the progress is displayed in the r console. but i am not able to see the progress status in matlab screen when i call the R script from Matlab.
how can i see the progress of running the R script.
is there any command for that?
You need to specify the '-echo' option when using the system command
[status,cmdout] = system(command,'-echo')
http://nl.mathworks.com/help/matlab/ref/system.html
I've used the system function with the -echo option to run ffmpeg from the matlab command window, and the resulting command window output is the identical to what I see in the cmd.exe console.
If this doesn't resolve the issue, can you post some example code of what your doing?

Running R file that has Dependencies From Linux Command Line

Let say that I have a file
file1.R and it has a method getMe()
Now, I want to run file2.R and it makes calls to getMe()
Do I need to run
R CMD BATCH file1.R
before whenever I want to run
R CMD BATCH file2.R ?
Or will R some how be able to determine that file2 has a function that is defined in file1.R?
Whats the standard for running a file that has other function dependencies in other files?
You need to source file1.R so that the functions defined there becomes available for others.
source('file1.R')
You can do this inside your file2.R. Then run simply
R CMD BATCH file2.R

Problems executing script from command line in R. Error message: cannot find path specified

I have been trying to execute a simple test.R
setwd("C:\Users\jdd\Documents")
test <- 2*6598
filename = "test.csv"
write.csv(test,file=filename)
Via the following command line command in Windows:
"C:\Program Files\R\R-2.15.2\bin\R.exe" CMD BATCH --vanilla --slave "C:\Users\jdd\Documents\test.R"
When I execute this I get the following error:
The system cannot find the path specified.
I have been trying to work out a solution on the basis of the provided error message, but failed so far. Wondering if somebody can help me so I can execute the script directly from the command line. Thanks
Thanks #sebastian-c! I tried to use RScript, which I investigated before. However, the problem was a different one. Appears that in my installation there is a R.exe and Rscript.exe file in .\bin, but also one in .\bin\x64. The first one is not working properly, but the second one is. The comment made by #Roland is very important as well, since once working I got this error message!
The following command did the job:
"C:\Program Files\R\R-2.15.2\bin\x64\Rscript.exe" "C:\Users\jdd\Documents\test.R"
and the corrected text.R is:
setwd("C:\\Users\\jdd\\Documents")
test <- 2*6598
filename = "test.csv"
write.csv(test,file=filename)
As mentioned here, it might has something to do with 64bit version of R.
The problem is that Rscript.exe itself is attempting to access a missing file on the system. The obvious fix is explicitly add 'x64' to the path of the other Rscript.exe that was installed:
"C:\Program Files\R\R-2.15.2\bin\x64\Rscript.exe" --version
R scripting front-end version 3.0.2 (2013-09-25)

Resources