MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / checkRDependencies

Method checkRDependencies

src/topp/MetaProSIP.cpp:1936–2017  ·  view source on GitHub ↗

Perform a simple check if R and all R dependencies are there

Source from the content-addressed store, hash-verified

1934public:
1935 // Perform a simple check if R and all R dependencies are there
1936 static bool checkRDependencies(const String& tmp_path, StringList package_names, const QString& executable = QString("R"))
1937 {
1938 String random_name = String::random(8);
1939 String script_filename = tmp_path + String("/") + random_name + String(".R");
1940
1941 // check if R in path and can be executed
1942 TextFile checkRInPath;
1943 checkRInPath.addLine("q()");
1944 checkRInPath.store(script_filename);
1945
1946 OPENMS_LOG_INFO << "Checking R...";
1947 {
1948 QProcess p;
1949 p.setProcessChannelMode(QProcess::MergedChannels);
1950 QStringList env = QProcess::systemEnvironment();
1951 env << QString("R_LIBS=") + tmp_path.toQString();
1952 p.setEnvironment(env);
1953
1954 QStringList checkRinPathQParam;
1955 checkRinPathQParam << "--vanilla" << "--quiet" << "--slave" << "--file=" + script_filename.toQString();
1956 p.start(executable, checkRinPathQParam);
1957 p.waitForFinished(-1);
1958
1959 if (p.error() == QProcess::FailedToStart || p.exitStatus() == QProcess::CrashExit || p.exitCode() != 0)
1960 {
1961 OPENMS_LOG_INFO << " failed" << std::endl;
1962 OPENMS_LOG_ERROR << "Can't execute R. Do you have R installed? Check if the path to R is in your system path variable." << std::endl;
1963 return false;
1964 }
1965 OPENMS_LOG_INFO << " success" << std::endl;
1966 }
1967 // check dependencies
1968 OPENMS_LOG_INFO << "Checking R dependencies. If package is not found we will try to install it in your temp directory...";
1969 TextFile current_script;
1970 current_script.addLine("LoadOrInstallPackage <-function(x)");
1971 current_script.addLine("{");
1972 current_script.addLine(" x <-as.character(substitute(x))");
1973 current_script.addLine(" if (isTRUE(x %in%.packages(all.available = TRUE)))");
1974 current_script.addLine(" {");
1975 current_script.addLine(" eval(parse(text = paste(\"library(\", x, \")\", sep = \"\")))");
1976 current_script.addLine(" }");
1977 current_script.addLine(" else");
1978 current_script.addLine(" {");
1979 current_script.addLine(" options(repos = structure(c(CRAN = \"http://cran.rstudio.com/\")))");
1980 current_script.addLine(" update.packages()");
1981 current_script.addLine(" eval(parse(text = paste(\"install.packages('\", x, \"')\", sep = \"\")))");
1982 current_script.addLine(" eval(parse(text = paste(\"library(\", x, \")\", sep = \"\")))");
1983 current_script.addLine(" }");
1984 current_script.addLine("}");
1985 for (StringList::const_iterator it = package_names.begin(); it != package_names.end(); ++it)
1986 {
1987 current_script.addLine("LoadOrInstallPackage(" + *it + ")");
1988 }
1989
1990 current_script.store(script_filename);
1991
1992 QProcess p;
1993 p.setProcessChannelMode(QProcess::MergedChannels);

Callers

nothing calls this directly

Calls 9

randomFunction · 0.85
QStringClass · 0.50
StringClass · 0.50
storeMethod · 0.45
toQStringMethod · 0.45
startMethod · 0.45
errorMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected