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

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

Related

Error in excel charts when overwrite data from R

I am trying to automate some of my tests in R to produce a static report in Excel. I have created a template in Excel which has a few charts and tables(sheet 1).
Now I run my R code to generate the data to fill in the same excel template file on Sheet 2.
I am using Openxlsx package to loadworkbook(excel template), next I overwrite data in sheet 2 by deleting the sheet and recreating it again with the new data so that the excel template has data for new test runs.
This runs without any error. But when I open my excel back the charts disappear with the !REF# error whereas as the tables are overwritten properly in the template(sheet1).
Has anyone come across such a scenario? The method I am using is a bit weird but can't think of any other alternative.
Thanks in advance!!
This definitely sounds weird. Something seems off, but I'm sorry I can't tell you what the issue may be. Anyway, I would say, just use R to generate the data and dump everything into Excel. Then, run some VBA in Excel to create the charts. I have no idea what your VBA skills are like, but I'm guessing it would be much easier to crate charts in Excel using VBA, rather than trying to do all of this with R.
Here are a few resources that you may find useful.
https://www.thespreadsheetguru.com/blog/2015/3/1/the-vba-coding-guide-for-excel-charts-graph
https://analysistabs.com/excel-vba/chart-examples-tutorials/
http://www.sthda.com/english/wiki/r-xlsx-package-a-quick-start-guide-to-manipulate-excel-files-in-r
Finally, you can learn a lot by recording Macros and hitting F8 to step-through the code to see how everything works.

How to schedule the run of r script which reads data from postgres database, do some analysis and write resulting data to the database?

I have written a r script file, which reads in data from PostgreSQL database, do some analysis, predict the dependent variable and write back the results into the database. Now, I want to run that script file at fixed intervals. How to achieve this? Is there any way to run this from PostgreSQL or any other way to run this? Please help me.
Try this one:
https://github.com/bnosac/cronR - Unix/Linux
https://github.com/bnosac/taskscheduleR - Win

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

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.

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.

Is there a way to load rda/RData data from R into SAS?

I have plenty of .rda and .RData files from R statistical packageand would like to read them into SAS. Is there an (easy) way to do this?
If you can get R installed, then you could execute R code within PROC IML (assuming your SAS installation is configured properly, which can be a problem), read the results into e.g. a R data.frame and get the results back as described in the SAS documentation examples. If you do not have the SAS/IML license but have R, write the output out from R into some format SAS reads easily (e.g. csv). If you cannot get R installed on your system, can someone else with R installed do that for you?
Otherwise, you may have to write a SAS program that can parse the RData format. However, that would be a measure of desperation. I believe you would find the documentation of the format here and some discussion of the not so clear documentation here (see also)

Resources