-
-
Notifications
You must be signed in to change notification settings - Fork 288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docs:How do I replay cmdlogs on arbitrary files? #1606
Comments
I think there is a better example, but here is what I found after a speedy search: on the command line say |
@frosencrantz, thanks for the suggestion. Sorry for taking so long to get back to you on this. For my use case the solution is:
Here are some silly simple files for testing.
$ cat /tmp/abc1.csv
a,b,c
1,1,1
1,1,1
1,1,1
$ cat /tmp/abc2.csv
a,b,c
2,2,2
2,2,2
2,2,2
$ cat /tmp/cmdlog.vdj
#!vd -p
{"longname": "open-file", "input": "/tmp/abc1.csv", "keystrokes": "o"}
{"sheet": "abc1", "col": "a", "row": "", "longname": "freq-col", "input": "", "keystrokes": "Shift+F", "comment": "open Frequency Table grouped on current column, with aggregations of other columns"}
{"sheet": "abc1_a_freq", "col": "", "row": "", "longname": "transpose", "input": "", "comment": "open new sheet with rows and columns transposed"} In the following tests I use the The When I replay the cmdlog without any file inputs I get the expected result.
Same behavior when I specify
When I specify
I want the cmdlog to operate on whatever file is specified as input. I try to acheive that by just removing the open-file command. $ cat /tmp/cmdlog.vdj
#!vd -p
{"sheet": "abc1", "col": "a", "row": "", "longname": "freq-col", "input": "", "keystrokes": "Shift+F", "comment": "open Frequency Table grouped on current column, with aggregations of other columns"}
{"sheet": "abc1_a_freq", "col": "", "row": "", "longname": "transpose", "input": "", "comment": "open new sheet with rows and columns transposed"} Now when I play the cmdlog without an explicit file I get an error. That is what I would expect. $ vd -b -p /tmp/cmdlog.vdj -o -
opening /tmp/cmdlog.vdj as vdj
no sheet named abc1
replay canceled When I specificy $ vd -b -p /tmp/cmdlog.vdj /tmp/abc1.csv -o -
opening /tmp/abc1.csv as csv
opening /tmp/cmdlog.vdj as vdj
open Frequency Table grouped on current column, with aggregations of other columns
open new sheet with rows and columns transposed
replay complete
saving 1 sheets to - as tsv
a 1
count [3] [3] 1; 1; 1; [3] 1; 1; 1; [3] 1; 1; 1
percent 100.0
histogram **************************************************
- save finished When I specify $ vd -b -p /tmp/cmdlog.vdj /tmp/abc2.csv -o -
opening /tmp/abc2.csv as csv
A likely story indeed!
opening /tmp/cmdlog.vdj as vdj
no sheet named abc1
replay canceled Just for fun, I change the sheet names starting with $ cat /tmp/cmdlog.vdj
#!vd -p
{"sheet": "abc2", "col": "a", "row": "", "longname": "freq-col", "input": "", "keystrokes": "Shift+F", "comment": "open Frequency Table grouped on current column, with aggregations of other columns"}
{"sheet": "abc2_a_freq", "col": "", "row": "", "longname": "transpose", "input": "", "comment": "open new sheet with rows and columns transposed"} Now when I specify $ vd -b -p /tmp/cmdlog.vdj /tmp/abc2.csv -o -
opening /tmp/abc2.csv as csv
opening /tmp/cmdlog.vdj as vdj
open Frequency Table grouped on current column, with aggregations of other columns
open new sheet with rows and columns transposed
replay complete
saving 1 sheets to - as tsv
a 2
count [3] [3] 2; 2; 2; [3] 2; 2; 2; [3] 2; 2; 2
percent 100.0
histogram **************************************************
- save finished Opening a file puts a sheet on the stack. Creating a frequency table puts another sheet on the stack. Opening a file generates a sheet named after the file. A new sheet generated from an old sheet is named with the old sheet name as a prefix. To make it work with both input files I need to leave the sheet names blank. This makes Visidata use the sheet at the top of the stack whatever its name is. $ cat /tmp/cmdlog.vdj
#!vd -p
{"sheet": "", "col": "a", "row": "", "longname": "freq-col", "input": "", "keystrokes": "Shift+F", "comment": "open Frequency Table grouped on current column, with aggregations of other columns"}
{"sheet": "", "col": "", "row": "", "longname": "transpose", "input": "", "comment": "open new sheet with rows and columns transposed"} Now playing the command log without an input file causes an error. This is what I expect. $ vd -b -p /tmp/cmdlog.vdj -o -
opening /tmp/cmdlog.vdj as vdj
no "a" column
replay canceled When $ vd -b -p /tmp/cmdlog.vdj /tmp/abc1.csv -o -
opening /tmp/abc1.csv as csv
opening /tmp/cmdlog.vdj as vdj
open Frequency Table grouped on current column, with aggregations of other columns
open new sheet with rows and columns transposed
replay complete
saving 1 sheets to - as tsv
a 1
count [3] [3] 1; 1; 1; [3] 1; 1; 1; [3] 1; 1; 1
percent 100.0
histogram **************************************************
- save finished And it works with $ vd -b -p /tmp/cmdlog.vdj /tmp/abc2.csv -o -
opening /tmp/abc2.csv as csv
opening /tmp/cmdlog.vdj as vdj
open Frequency Table grouped on current column, with aggregations of other columns
open new sheet with rows and columns transposed
replay complete
saving 1 sheets to - as tsv
a 2
count [3] [3] 2; 2; 2; [3] 2; 2; 2; [3] 2; 2; 2
percent 100.0
Pay attention.
histogram **************************************************
- save finished |
This is so cool @iainelder, thanks for documenting all of this! |
Thanks @anjakefala . I didn't find an example of this use case in the help output or in the Introduction to Visidata or in the Getting Started docs. Did I miss something? If not, I think it would be helpful to include it using some more meaningful data. The ability to replay cmdlogs for me is a compelling feature because it facilitates reproducible analysis. So does arbitrary scripting, but Visidata's display features make it easier to see what is going on step-by-step, so it makes it easier to learn about my data. |
@iainelder I re-opened the issue so we do not forget to update the docs, you are right! |
I see cmdlogs introduced here: https://github.com/saulpw/visidata/blob/develop/docs/save-restore.md Would this be a good place to extend the documentation? Or would you add a new page to cover the use case? |
That would be a great place! |
The "save and replay" page already has a screencast using sample.tsv that generates a cmdlog. How about we make a new screencast that
|
Also, @iainelder, what would be a good root solution to this? I've added the |
@saulpw for me the first problem was that it hadn't occurred to me that opening a file would be treated as a command. I can see why such a command is useful, but I wasn't expecting it to be included in my cmdlog, at least by default. The next problem was to learn about the stack of sheets and that sheets have autogenerated names. I don't actively change sheets in my analyses, so the fact that sheets have names and those names have to match in the cmdlog feels like I'm being exposed to implementation details rather than just a list of my commands. (I'm sure there are plenty of use cases for actively changing sheets, but I'm not there yet!) I'd like to try All I see is something in the CHANGELOG for version 2.10.2 but nothing in the online help. |
@iainelder Just save as |
@saulpw , I just had a look at the The sheet names sometimes still appear in absolute form, so it doesn't avoid that problem. Following the instructions I gave earlier, I get output like this in
If the intention is to reflect the commands that I issue explicitly, then I think the When I open a file, Visidata automatically names a sheet for the data and opens it. For me that's just part of the The same is true when I look at the frequencies. The Given these two above, I would have expected |
@iainelder I think you mean |
According to #572 this has been implemented, but from the comments on the issue I can't figure out how to do it, and I can't find any documentation.
I recorded some actions an Visidata wrote me a cmdlog file whose first few lines look like this:
It works only on the file names in the "open-file" command. I want it to work on any file with the same schema. I want to specify the file name at the command line.
I tried removing the "open-file" line and passing the
-o
option, but that produces no output at all.vd -o ~/tmp/stack_instances.json -p stack_instance_status_summary_histogram.vdj
The other issue talks about replacing a sheet name with null or 0, but I don't know what that means. In my example the sheet name is not always the same because some of the commands create new sheets.
The text was updated successfully, but these errors were encountered: