How to fetch data in R by executing command in excel? - r

I have to fetch data from Reuters and they provide an excel plugin for that. The problem is that my excel is crashing if I try to fetch too many variables at the same time. I was wondering whether I can do it from R via some excel connection.
In general I want to give the command to excel (from R), fetch data and get the data back in R for analysis. The process has to be repeated a number of times.
=TR("SCREEN(U(IN(Equity(active,public,primary))/*UNV:Public*/))",A1:K10,"PERIOD:FY2015 NULL:-- curn=USD RH=In CH=Fd",A6)
I get the variable name from (A1:K10) and then the output is stored from cell A6 onwards.
The answer https://stackoverflow.com/a/43222477/1389469 here points to RDCOMClient library but I am not able to run the macro from R as described there.
Another guide here https://cran.r-project.org/web/packages/excel.link/excel.link.pdf talks about how to read/write data from an open excel workbook but doesn't tell how to execute commands in excel from R.

Related

Saving Excel Table to OneDrive with R PowerQuery

I have a report that all it does is export it's data to excel via power automate using some R code.
"write_xlsx(dataset,"file_path.xlsx")"
However, I need to manipulate it further and it needs to be in a tabular format to do so. Yet, when I try "write.table" I get the error that my connection to OneDrive is not open. So I can export an Excel sheet with the data, but not the same data as a Table.
Any ideas?

Can R script be embedded in Tableau to produce a data set?

I'm trying to use R as data source for Tableau.
Meaning - my script generates a data set and I'd like to run this script in Tableau to generate the data source instead of connecting to csv file.
This can be easily done by Power BI, yet don't see this kind of option in Tableau.
There's the option of using R script in calculations but that's only once data set is already loaded.
Is there a way or a workaround?
Thank you in advance,
Alex

How to achieve the equivalent of Refresh All (in Excel) in R?

The title to this really says it all. I am trying to automate a report in R, ideally, the Excel file would be imported into R, refreshed (as the said Excel file has a direct link to SQL) before finally outputting the result as an Excel file.
Finally, this report needs to automatically run without human intervention or supervision (hence the need for R).
Any help or ideas would be appreciated !

How do I update multiple individual Excel files with PivotTables in R?

I built a script that pulls from the data warehouse and cleans the data in a format to be export as a csv file. I take the file and paste it into an Excel file that already has a PivotTable with slicers on another tab. The thing is that I am creating a report for every sales rep with their own sales using an Excel macro. There are 300 sales reps that I am sending this unique report to. Right now, I use an Excel VBA macro that creates individual reports and sends them to each sales rep via Outlook which takes a very long time and slows down my laptop.
Is there a way to use R to auto update an Excel file for each sales rep data and refreshes the PivotTable without having to open them individually? I also want to send an automated email which attaches the Excel file and sends to each sales rep via Outlook. I have done it for text and csv files via R but not in a loop manner to over 100 sales rep.
For sending data from R to Excel, I use excel.link package by Gregory Demin (I believe it is a Windows only package). I found it most useful. https://cran.r-project.org/web/packages/excel.link/excel.link.pdf
Here is example workflow on Windows:
Assuming you have a data.frame currently in your r session under object d
and you have an Excel workbook saved under c:\mybook.xlsb
# kill an existing Excel process running (if any)
shell("taskkill /im EXCEL.exe /f /t")
# open a workbook from 'c:\\mybook.xlsb'
xl.workbook.open("c:\\mybook.xlsb")
xl.workbook.activate("mybook.xlsb")
mybook = xl.get.excel()
# paste the data from dataframe object `d` to the active sheet in cell (1,1) which corresponds to cell A1
xl.write(d,row.names=FALSE,xl.rng=mybook[["Activesheet"]]$Cells(1,1))
# activate a different sheet named 'mysheet'
xl.sheet.activate("mysheet")
# do more stuff with 'mysheet' here...
# save your workbook to a different copy once done
xl.workbook.save("c:\mybook_current_version".xlsb"))
# kill Excel process again to quit Excel
shell("taskkill /im EXCEL.exe /f /t")
Check the documentation for more examples.
For sending e-mails with attachments, look at sendmailR package.

How to Import statistica data (*.sta) into R

I'm a master student and I'm having a course in statistics with the program STATISTICA. I am rather familiar with R and would like to stick to it. So I am planning to do the provided exercises in R. However the data to work with is in the format *.sta... is there a way to import such a file into R? Any workaround is also fine, as long as it doesn't compromise the data.
I actually found the same question 2 years ago here but there was no answer to it.
I'd be very happy for any suggestions!
Thanks
Lukas
If R does not support importing Statistica Spreadsheet files (.sta files), Statistica supports exporting data to .xlsx, .csv, and SPSS and SAS format files. I would think that one of those would be able to be handled by R natively.
If you enable Statistica-R integration through Statistica, a package called COMadaptR will be installed to R.
Once that is done, you have a couple of options:
You can run your R script inside of Statistica using the extensions (provided by Statistica) ActiveDataSet or Spreadsheet to access the Statistica spreadsheet as an R data frame.
You can create an R node in a workspace; connect the Statistica spreadsheet to the R node in the workspace; and then run your R script through the node. ActiveDataSet and Spreadsheet will be available in the R node context as well.
You could write a small R script (and use ActiveDataSet or Spreadsheet) and run it in Statistica; the R integration features will translate the Statistica spreadsheet to an R data frame. You could then in your script store it to disk and work with it later.
The COMadaptR package will allow you to interact with Statistica through COM from within R; you could use that approach to read data from the Statistica spreadsheet.
Hope this helps.

Resources