language-extensions/R/src/RLibrarySession.cpp
//--------------------------------------------------------------------------------------------------
// Name: RLibrarySession::GenerateScriptToSetLibPath
//
// Description:
//  Creates a script that would set the libPaths to a character vector of strings.
//  These strings are the ordered members of the input Rcpp::CharacterVector and are directory paths.
//  If the given vector is empty, we simply return the default value of the script
//  which is .libPaths()
//
// Returns:
//  An R script that can be used to set the libPaths.
//
:GenerateScriptToSetLibPath
Description:
Creates a script that would set the libPaths to a character vector of strings.
These strings are the ordered members of the input Rcpp::CharacterVector and are directory paths.
If the given vector is empty, we simply return the default value of the script
which is .libPaths()

An R script that can be used to set the libPaths.
: GenerateScriptToSetLibPath Description : Creates a script that would set the libPaths to a character vector of strings . These strings are the ordered members of the input Rcpp :: CharacterVector and are directory paths . If the given vector is empty we simply return the default value of the script which is . libPaths () An R script that can be used to set the libPaths .
string RLibrarySession::GenerateScriptToSetLibPath(
	Rcpp::CharacterVector pathsVector,
	bool                  isLastElementLibPaths)
{
	stringstream setLibPaths;
	if (pathsVector.size() > 0)
	{
		setLibPaths << ".libPaths( c( ";
		for (int index = 0; index < pathsVector.size(); ++index)
		{
			 Do the processing only if the path is not empty
			if (!pathsVector[index].empty())
			{
				string normalizedPath = Utilities::NormalizePathString(
					string(pathsVector[index]));
				if (index != pathsVector.size() - 1)
				{
					 This is the case for all paths except the last one
					setLibPaths << "'" + normalizedPath + "', ";
				}
				else
				{
					if (isLastElementLibPaths)
					{
						 This is scenario A: if the last element is .libPaths()
						 then we don't need to enclose it in quotes.
						setLibPaths << normalizedPath;
					}
					else
					{
						 This is scenario B: if the last element is a regular path,
						 we need to enclose it in quotes but not add a ','
						setLibPaths << "'" + normalizedPath + "'";
					}
				}
			}
		}
		setLibPaths << " ) );";
	}
	else
	{
		 Use the default get lib paths scripts as the same script to set lib paths
		 when size of given Rcpp::CharacterVector is 0.
		setLibPaths << sm_ScriptToGetLibPaths;
	}
	return setLibPaths.str();
}
string RLibrarySession :: GenerateScriptToSetLibPath ( Rcpp :: CharacterVector pathsVector , bool isLastElementLibPaths ) { stringstream setLibPaths ; if ( pathsVector . size ( ) > 0 ) { setLibPaths << " " ; for ( int index = 0 ; index < pathsVector . size ( ) ; ++ index ) { if ( ! pathsVector [ index ] . empty ( ) ) { string normalizedPath = Utilities :: NormalizePathString ( string ( pathsVector [ index ] ) ) ; if ( index != pathsVector . size ( ) - 1 ) { setLibPaths << " " + normalizedPath + " " ; } else { if ( isLastElementLibPaths ) { setLibPaths << normalizedPath ; } else { setLibPaths << " " + normalizedPath + " " ; } } } } setLibPaths << " " ; } else { setLibPaths << sm_ScriptToGetLibPaths ; } return setLibPaths . str ( ) ; }
Name: RLibrarySession::GenerateScriptToSetLibPath
Description:
Creates a script that would set the libPaths to a character vector of strings.
Name : RLibrarySession :: GenerateScriptToSetLibPath Description : Creates a script that would set the libPaths to a character vector of strings .
// The script looks like either of the two scenarios : // A) .libPaths( c( 'Path1', 'Path2', .libPaths())); OR // B) .libPaths( c( 'Path1', 'Path2', 'Path3')); // // Do the processing only if the path is not empty // // This is the case for all paths except the last one // // This is scenario A: if the last element is .libPaths() // then we don't need to enclose it in quotes. // // This is scenario B: if the last element is a regular path, // we need to enclose it in quotes but not add a ',' // // Use the default get lib paths scripts as the same script to set lib paths // when size of given Rcpp::CharacterVector is 0. //