Reading in an Excel file with multiple tabs in R - import-from-excel

I've browsed and browsed but cant seem to find a solution on here that fits my case. I have an Excel file with 4 tabs. Each tab is formatted exactly the same- 2 columns and 12 rows (including headers). The columns headers are all titled as "Slow Times" and "Fast Times", respectively, then contain some numbers. I've been able to load the excel file and see that the tabs are also imported, but I'm unsure how to reference each tab once they're loaded. So far I have:
sheets <- excel_sheets("mydata.xlsx")
list_all <- lapply(sheets, function(x) read_excel("mydata.xlsx", sheet = x))
list_all

Related

Importing .csv WITHOUT the NA in empty cells

Six years ago this guy asked my question...
Getting rid of NA values in R when importing a CSV file
...but no final answer showed up because he never displayed his data
Here is an image of my data in a.csv file. If you need it as code, just say so and I will supply (I just used the RAND() function in Excel to create it).
There are no "missing values" in the usual sense. It just that some columns have more, others less. I will never need to invert so it need not be rectangular. All the "empty" cells are always at the bottom. AND rm.na does not work as I need to operate on each column separately with a special function that does not take rm.na as an argument. How can I import this into R with NOTHING in the cells which are empty. I have tried readxl, RStudio, using Excel instead of .csv, lots of different approaches. Most of them want me to eliminate rows with NA in them. That does not work, either.
Thanks for anyone who can help

Convert spreadsheet to .csv on command line without evaluating formulas

I want to convert a spreadsheet (e.g. .xls or from LibreOffice Calc) to some text format, e.g. .csv, without evaluating formulas so the formulas are stored in the text file. I know that LibreOffice has an option "Save cell formula instead of calculated values" when saving as .csv and according to How to export spreadsheet to CSV without evaluating formulas Excel can do this too, but I'd like to do it on command line. I know that ssconvert from the Gnumeric package can convert on command line but as fa as I ca see there's no option to keep the formulas.
The bigger picture is that I want to write a script that takes two versions of an .ods file, converts them and shows the differences. When only one cell has really changed but many other cells depend on it, then I want to see only the real change.
I have used xls2csv under Cygwin. Just a Google search shows many implementations. I would start there.
http://search.cpan.org/~ken/xls2csv-1.07/script/xls2csv

Excel files generated from iReport

Is there something that i have to add to iReport so my file will be able to use all the columns of the excel file ?
Example :
When i download a big excel file(a report made with iReport) from the application it uses all the excel columns from A to Z then it returns to the next line. I want to make it use the AA , AB , AC , AD ect columns that still available in excel because i don't want line returns.
Is it even possible ?
In case somebody else needed the answer , i made the band's width bigger (20000) to reach all the excel columns .
Problem resolved .

Talend tFileOutputdelimited component - problems with the split .csv files

I tried my luck on the Talend forum and no luck there, so I will try here as well.
I have a job that is reading a large table and then writing the data to .csv files in increments of 25000 rows. What I have noticed is that all .csv files created after the first .csv file have the data loaded all in one row versus the first .csv file that has the data loaded in 25000 rows (as I want it).
Is there a setting that needs to get set on the tFileOutputDelimited component that will allow for the rows in all subsequent .csv files to get loaded as they are in the first (and 'good') .csv file? I am thinking it may be due to what is being used for the 'Escape char' value on the 'Advance settings' tab but am not sure.
On the tFileOutputDelimited component's 'Basic settings' tab, the CSV Row Separator value is CRLF("\r\n") and the field separator is ",". On the component's 'Advanced settings' tab, the Escape char value is """ and the Text enclosure value also is """.
Also, this is being run in a Windows 7 environment.
Unfortunately the documentation I found for the tFileOutputDelimited component's 'Advance settings' tab is lacking in regards to the CSV options.
Below is an example of what is being encountered. As listed below, the first file looks great but all files that follow do not break on the line break and end up placing all of the data on one row versus individual rows.
File #1
header row
row 1
row 2
row 3
...
row 25000
File #2...
header rowrow1row2...row25000
File #3...
header rowrow1row2...row25000
If you need more details, let me know and I'll send them right off. Thank you in advance.
Figured it out. As mentioned in my initial post, the CSV Row Separator had been set to the CRLF("\r\n") option. I changed this to the LF("\n") and that addressed the problem. I had looked atthe generated java code and noticed that it was not treating the CRLF("\r\n") as one of the default options - only \n and \r were. This pointed me in the direction of trying the \n option.

Is it possible to show the contents of a text file in Crystal Reports

I have a crystal report which contains a list of absolutely referenced text files. There is one text file referenced in each body line.
e.g.
line1 c:\file1.txt
line2 c:\file2.txt
Is there any way to display the contents of these files in Crystal?
i.e. I would like each crystal body line to show the text from the referenced text file.
I'm using Crystal reports 11 with a non-standard database connector (dataflex).
You would need to set up a file dsn (in XP it's under Control Panel/Administrative Tools/Datasources (ODBC)) and then use the file dsn (Microsoft Text Driver) for the datasource as an ODBC(RDO) connection.
I set this test scenario up on mine like the following:
**File 1**
column1
1row1
1row2
1row3
**File 2**
column1
2row1
2row2
2row3
I set up the file dsn to point to the c drive and in the datasource screen I added file1.txt and file2.txt to the selected tables. Then the easiest thing to do is clear the links of the tables so that it pulls every row. It will warn you that there are multiple starting points. I don't generally recomend this, but it will work in this case and since it's not reporting off a database it probably isn't the end of the world. If you disregard the starting point message then add the fields to the report, when you run it you should get the following output:
1row1 2row1
1row1 2row2
1row1 2row3
1row2 2row1
1row2 2row2
1row2 2row3
1row3 2row1
1row3 2row2
1row3 2row3
From this you can change your grouping to get the output that you need.
You can also use this same connect against subreports instead of doing this linking where you have the main report pull the info from file1.txt and then put a subreport in the report footer that pulls from file2.txt. This option won't have the text collated, but you'd still have it in the same report.
Hope this helps some.
It's easier than you think. I just set up one myself before I wrote this to make sure I was giving you the right steps. Using CR version XI and a .txt file, I followed these steps:
For each text file you want to import, make a subsection in your report (i.e. DetailsA, DetailsB, etc.). If your list of text files is constantly changing (and I don't think it is, based on your description), you'll need another method.
Make sure your text file is comma delimited and the first row contains field names. If these text files are actually text (i.e. not tables), then just put a dummy variable name in the first row so Crystal will see the text as a table of data with just 1 row.
For each text file you want to display, create a new Subreport (Insert->Subreport)
In the database selection menu, go to "Create New Connection"->"Access/Excel (DAO)"
Under 'database type', you'll see a 'text' option at the bottom of the screen.
Choose your file.
Relax! (I'm in a good mood this morning, don't know why)
I guess if you have a function that takes a file name as an argument and returns the contents of that file - you could use that function in a Crystal Report formula.
I am not familiar with the current CR, it has been years since I last used it (I last used version 8). In the versions I did use, such a function was not built in. What you would have to do back then, was to create a UFL (user function library) containing the functions you needed. If I remember correctly, you had to do this using COM.
In this day and age, I guess you can extend CR using some other mechanism, perhaps writing .NET code?
I suggest you search the CR documentation for the term UFL.
Another suggestion, then:
Create a new table FILECONTENTS (filename varchar primary key, contents blob)
Create a script that on a schedule populates this table with the filenames and contents of all the files (assuming that there is a finite number of files, and that you have a way of knowing about them)
Modify the report datasource query to join it with the FILECONTENTS table, and add the contents field to the report.
You could setup a file dsn. But this is geared toward tabular file data, not text.
How big are these text files? You want to display the entire contents of each file?
There is probably no easy way to dynamically read in a file from within crystal. You will most likely have to push a dataset to the report which contains the file contents.