language-extensions/R/src/RLibrarySession.cpp
//--------------------------------------------------------------------------------------------------
// Name: RLibrarySession::IsLibraryInstalledAtPath
//
// Description:
//  Checks if the library is installed at the correct location or not by executing
//  the script find.package()
//  If the library is installed, this script returns its first installation location.
//  If its installed location is same as the installDir, it returns true.
//  Otherwise, it returns false.
//
// Returns:
//  True if installed at correct location, false otherwise.
//
:IsLibraryInstalledAtPath
Description:
Checks if the library is installed at the correct location or not by executing
the script find.package()
If the library is installed, this script returns its first installation location.
If its installed location is same as the installDir, it returns true.
Otherwise, it returns false.

True if installed at correct location, false otherwise.
: IsLibraryInstalledAtPath Description : Checks if the library is installed at the correct location or not by executing the script find . package () If the library is installed this script returns its first installation location . If its installed location is same as the installDir it returns true . Otherwise it returns false . True if installed at correct location false otherwise .
bool RLibrarySession::IsLibraryInstalledAtPath(const string &installDir)
{
	LOG("RLibrarySession::IsLibraryInstalledAtPath");
	string getInstallationLocationScript = "find.package(package = '" + m_libraryName + "'"
		", lib.loc = '" + installDir + "')[1];";
	bool isInstalled = false;
	try
	{
		Rcpp::CharacterVector installedLocationVector(
			ExecuteScriptAndGetResult(getInstallationLocationScript));
		if (installedLocationVector.size() > 0)
		{
			string firstInstallPath(installedLocationVector[0]);
			LOG(m_libraryName + " is found installed at " + firstInstallPath);
			fs::path fullExpectedInstallPath = fs::path(installDir) / m_libraryName;
			string normalizedFoundPath =
				Utilities::NormalizePathString(firstInstallPath);
			string normalizedExpectedInstallPath =
				Utilities::NormalizePathString(fullExpectedInstallPath.string());
			isInstalled =
				normalizedFoundPath.compare(normalizedExpectedInstallPath) == 0;
		}
	}
	catch (...)
	{
		LOG(m_libraryName + " is not installed.");
	}
	return isInstalled;
}
bool RLibrarySession :: IsLibraryInstalledAtPath ( const string & installDir ) { LOG ( " " ) ; string getInstallationLocationScript = " " + m_libraryName + " " " " + installDir + " " ; bool isInstalled = false ; try { Rcpp :: CharacterVector installedLocationVector ( ExecuteScriptAndGetResult ( getInstallationLocationScript ) ) ; if ( installedLocationVector . size ( ) > 0 ) { string firstInstallPath ( installedLocationVector [ 0 ] ) ; LOG ( m_libraryName + " " + firstInstallPath ) ; fs :: path fullExpectedInstallPath = fs :: path ( installDir ) / m_libraryName ; string normalizedFoundPath = Utilities :: NormalizePathString ( firstInstallPath ) ; string normalizedExpectedInstallPath = Utilities :: NormalizePathString ( fullExpectedInstallPath . string ( ) ) ; isInstalled = normalizedFoundPath . compare ( normalizedExpectedInstallPath ) == 0 ; } } catch ( ... ) { LOG ( m_libraryName + " " ) ; } return isInstalled ; }
Name: RLibrarySession::IsLibraryInstalledAtPath
Description:
Checks if the library is installed at the correct location or not by executing
the script find.package()
If the library is installed, this script returns its first installation location.
Name : RLibrarySession :: IsLibraryInstalledAtPath Description : Checks if the library is installed at the correct location or not by executing the script find . package () If the library is installed this script returns its first installation location .
// If the script throws an exception, it means we could not find the package. // Keep isInstalled = false. //