- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Multiple File Import Auto-Naming Data Table
Hello All,
I'm writing a script where I start with a 'multiple file import' of a folder of .csv files. I will periodically be getting new .csv files that I would like to add. These files have a series of letters and numbers (i.e chghistory0857-786.csv, chghistory0956-783.csv, chghistory1008-805.csv, etc). The issue I'm running into is when I run the 'multiple file import' script, JMP creates a data table name that is auto named based on the .csv file names (i.e. chghistory0956-783_chghistory1008-805). When I put more data files into the folder, this name changes and messes up all future formulas.
Is there a way to pre-establish the data table name and have the data from the MFI dumped into it? JMP16 user here if that makes a difference.
Thank you,
Greg
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Multiple File Import Auto-Naming Data Table
You bet. Multiple File Import returns a reference to the table that's created. You can use that to change the name, e.g.,
tblRef = Multiple File Import(...
);
tblRef << Set Name("My New Name");
You could work directly with the reference variable. This way you don't have to worry about what the table is named.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Multiple File Import Auto-Naming Data Table
You bet. Multiple File Import returns a reference to the table that's created. You can use that to change the name, e.g.,
tblRef = Multiple File Import(...
);
tblRef << Set Name("My New Name");
You could work directly with the reference variable. This way you don't have to worry about what the table is named.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Multiple File Import Auto-Naming Data Table
Thank you! This worked great, I will also experiment with using reference variables but this was a quick fix.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Multiple File Import Auto-Naming Data Table
In Addition to @DonMcCormack you probably need to check what type of data you get back. In this case it is a list.
It's always better to work with specific references directly from the command before, because static names can be problematic. See Screenshot, as data table "Animals" already existed, the last import created "Animals 2".
Scripting Index is great to see how this works, even you can test some variations.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Multiple File Import Auto-Naming Data Table
MFI always returns a { list of tables } even if there is only a single table. In @DonMcCormack answer, the <<setName is sent to every table in the list. You might want to (1) check that the list has exactly one item and (2) pull the item out of the list.
if( nitems(tblRef) != 1, throw("Bummer: MFI did not return exactly one table. The CSV files are not importing as expected.") );
tblRef = tblRef[1];
tblRef << Set Name( ... )
If you get that throw in a couple of years, it might only take an hour to fix rather than a day to track down why it no longer works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Multiple File Import Auto-Naming Data Table
This method works to a point. When I do this, I can't use "Close(tblRef, NoSave)" to close the table. Can you? My method is to set the reference after the import as "tblRef = Current Data Table();". This seems to be a bug in JMP 16.2 and JMP 17.0.0.
Thoughts?
Martin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Multiple File Import Auto-Naming Data Table
Take a look at @Craige_Hales post above. You may have to use something like Close(tblRef[1],No Save) (or index the tables from the list that Multiple File Import generates). If this doesn't work, I'd be interested to know the circumstances.
Thanks! Don
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Multiple File Import Auto-Naming Data Table
what if multiple files are opened instead of 1. How can you address that issue?
Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Multiple File Import Auto-Naming Data Table
actually, no issue. You can use the described approach.
You just have to take care that the N data tables can't have all the same name:
Jmp will add numbers to make them distinct.
Same issue if you want to rename a single data table - and the name is already used for another data table.
Best practice: use te table reference to reference the data table - NOT the name.
If you want to use the name - always ask a data table for the name (after set name).
Same "issue" with column names:
Don't trust the column << set name
tblRef << set name("myname");
tblRef << get name()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Multiple File Import Auto-Naming Data Table
It actually did not work with me and kept prompting me with the "unrecognized message" error.