`rmpath` removes current path from search path

Problem description

I have just started using Octave for running my Matlab (R2020b) codes. I am getting started with my use of Octave by running a simple function (“run_fun_092421.m”). The function runs successfully for the first time. When run the second time, it gives and error and thus fails to run.


Elapsed time is 0.0367429 seconds.


error: ‘run_fun_092421’ undefined near line 1, column 1

I have repeated running this function several times by now. Every time I get the same outcome: it runs successfully at the first time, but produces the error and fails.

Any help to fix this error would be greatly appreciated. Thanks!
run_fun_092421.m (807 Bytes)

#My system:

  • OS: Windows 10 Enterprise -64bit
  • Octave version: Version 6.2.0
  • Installation method: Downloaded and installed “octave-6.2.0-w64-64-installer” from Download

I confirm that with a simpler example with function a at the current path:

>> a
ans = 1
>> pwd
ans = C:\Users\Markus
>> rmpath('..\Markus')
>> a
error: 'a' undefined near line 1, column 1

It looks like the current path is removed from the search path by rmpath('..\Markus').
That should never happen.

Could you please open a bug report at savannah for that?
GNU Octave - Bugs: Submit Item [Savannah]

For the time being, removing the rmpath command from your script should prevent this from happening for you.
Alternatively, you could add the current path to the search path again with this command:

1 Like

What happens if you comment out the addpath and rmpath lines?

Thanks very much @mmuetzel!

If you take a look at the code I supplied at the time of posting my help request, I have a statement with addpath(…) in the beginning and a statement rmpath(…) in the code (and I am sure you may have noticed it). So, my experience with running this code (or any code that had these two addpath/rmpath statements) in Matlab tells me that whenever (1st time, 2nd time, etc.) the code may be run in Octave, it should execute the addpath and rmpath statements. So, my question would be why the addpath statement runs for the first time but not the next time.

@dastew Commenting out the addpath/rmpath statements in my sample code does not throw any error regardless the number of times I run the code.

So, @mmuetzel you suggest that I should report this error message as a bug? To me, it seems it is a bug.

I’m assuming that the function is in the current directory for your tests. It was for mine.
When executing the function the first time, it can be found because the current directory (.) is still in the search path (path()).
During the execution of the function, the call to rmpath effectively removes the current directory from the search path. (That is a bug.)
That means that it cannot be found in the (updated) search path when you try to execute it again. Actually no function in the current directory can be executed at that point.
Because the function can’t be executed, the addpath command is never reached.

I opened a bug report here:
bug #61216, “rmpath” can be used to remove the current path from the load path

Edit: That was an easier fix than expected. (I hope it doesn’t have unexpected side effects…)
A nightly build from tomorrow (2021-09-25) or later should contain that fix. You could download the nightlies from here:
Buildbot (octave.space)

1 Like