Skip to content
Snippets Groups Projects
Commit 9435d1d7 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Fix user_has_octave_forge_package

Packages are no longer autoloaded, so testing whether they are "Loaded" does
not work in all cases.

The function now ensures that the package is loaded.

This change was made for consistency with commit 7cbac0c9 in Dynare.
parent 8b956787
No related branches found
No related tags found
No related merge requests found
...@@ -46,14 +46,10 @@ if isoctave ...@@ -46,14 +46,10 @@ if isoctave
fclose(fid); fclose(fid);
if length(firstline) < 4097 if length(firstline) < 4097
if ~user_has_octave_forge_package('io') if ~user_has_octave_forge_package('io')
try
pkg load io
catch
error(['The io package is required to read CSV files from Octave. ' ... error(['The io package is required to read CSV files from Octave. ' ...
'It can be installed by running the following from the Octave ' ... 'It can be installed by running the following from the Octave ' ...
' command line: pkg install -forge io']); ' command line: pkg install -forge io']);
end end
end
A = csv2cell(file); A = csv2cell(file);
[data, T, L] = parsecell(A); [data, T, L] = parsecell(A);
withvars = L.numlimits(2,1) > L.txtlimits(2,1); withvars = L.numlimits(2,1) > L.txtlimits(2,1);
......
...@@ -45,14 +45,10 @@ if nargin<3 || isempty(range) ...@@ -45,14 +45,10 @@ if nargin<3 || isempty(range)
end end
if isoctave && ~user_has_octave_forge_package('io') if isoctave && ~user_has_octave_forge_package('io')
try
pkg load io
catch
error(['The io package is required to read CSV files from Octave. ' ... error(['The io package is required to read CSV files from Octave. ' ...
'It can be installed by running the following from the Octave ' ... 'It can be installed by running the following from the Octave ' ...
' command line: pkg install -forge io']); ' command line: pkg install -forge io']);
end end
end
% Check file extension. % Check file extension.
if ~(check_file_extension(file,'xls') || check_file_extension(file,'xlsx')) if ~(check_file_extension(file,'xls') || check_file_extension(file,'xlsx'))
......
...@@ -20,4 +20,11 @@ function [hasPackage] = user_has_octave_forge_package(package) ...@@ -20,4 +20,11 @@ function [hasPackage] = user_has_octave_forge_package(package)
[desc,flag] = pkg('describe', package); [desc,flag] = pkg('describe', package);
hasPackage = isequal(flag{1,1}, 'Loaded'); if isequal(flag{1,1}, 'Not installed')
\ No newline at end of file hasPackage = 0;
else
if isequal(flag{1,1}, 'Not loaded')
pkg('load', package);
end
hasPackage = 1;
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment