Menu

#247 Explain how to set the workdir (GUI & scripting) in the user guide

v1.0_(example)
closed
nobody
5
2021-04-11
2021-03-18
Iago Var
No

Hi, I've been trying to pass string variables values to commands and functions, particularly open and $workdir, but I was unable to do so. I searched for a solution in the documentation to no avail, also here in sourceforge.

This is basically what I intended to do: StackOverflow Thread.

Anyway, my intention was to do something like:

string file = "myfile.gdt"
string directory = "/path/to/directory"

set workdir =  $directory    # or something like that

open $file --preserve

also

string temp_open = directory ~ "/" ~ file

open $temp_open --preserve

delete temp_open

Maybe there's currently a way to do it, but honestly I spent quite a time with the documentation and I assumed it wasn't possible. I've looked to a bunch of scripts and everyone just puts open and workdir at the top of the script, which wasn't what I intended.

I needed this because I wanted to make an script for other to use, so I'll put a bunch of variables at the top, nicely put with comments, so they modify the variables, forget about it and run the script.

Discussion

  • Riccardo "Jack" Lucchetti

    You can use string substitution, as in

    string file = "myfile.gdt"
    string directory = "/path/to/directory"
    
    set workdir "@directory" 
    open "@file" --preserve
    

    Hope this helps

     

    Last edit: Riccardo "Jack" Lucchetti 2021-03-18
    • Iago Var

      Iago Var - 2021-03-18

      Thank you so much! I guess I glanced over it, quite a job to be focused so many pages :D

       
  • Sven Schreiber

    Sven Schreiber - 2021-03-18

    Hi, this is not really a feature request, but I assume that you're not aware of our mailing lists, which is our standard way of discussing such things. (I know some people prefer a web-based forum, but not the majority of our project.) Anyway, thanks for the pointer to the StackOverflow thread, I admit that lately we haven't paid attention to whether something was happening there under the gretl tag.
    OK, to your issues:
    1) string substitution: this has been pointed out by Jack already; for completeness: it should also work without the surrounding quotes here (open @file)
    2) File removal: delete only works for internal gretl objects, you need the remove() function for files.

    I agree that in the user guide it's not clear how to set the workdir, neither in the GUI nor via scripting. Implicitly it's explained in the command reference for the set command, but you'd already have to know that to find it, I guess. So I am going to turn this ticket into a (documentation) bug and change the title accordingly.
    BTW, it would be great if over on Stackoverflow you could add a comment that your questions have (hopefully) been answered, and how. Or notify us if that isn't possible.
    thanks
    sven

     
    • Iago Var

      Iago Var - 2021-03-18

      Hi, I tried to use the mailing list, but wasn't able to confirm my mail. I replied to mailman with the same subject, and tried different combinations of content, including null, to no avail.

      Also, I'll link to this URL in StackOverflow.

       
  • Sven Schreiber

    Sven Schreiber - 2021-03-18

    Ticket moved from /p/gretl/feature-requests/145/

     
  • Sven Schreiber

    Sven Schreiber - 2021-03-18
    • summary: Allow string variables to pass values to commands and functions --> Explain how to set the workdir (GUI & scripting) in the user guide
    • Group: --> v1.0_(example)
     
  • Sven Schreiber

    Sven Schreiber - 2021-04-11
    • status: open --> closed
     
  • Sven Schreiber

    Sven Schreiber - 2021-04-11

    Turns out that in the user guide the documentation of the File menu was outdated anyway, missing some newer items. One of those was "Working directory" which I have added now to the doc (along with the other missing ones). A cross-reference to the "set workdir" command is also given , so it should now be easier for users to find a way to change the workdir.
    So I'm closing this ticket.

     

Log in to post a comment.

MongoDB Logo MongoDB