Active Cells of Excel In RExcel - r

Cells in MS-Excel are always actives. Formulas update automatically when any value is modified. In R-Excel, I put data into R array/Dataframe and use it in a formula, and get the output.
When I change any data, I have to do all steps again to get the modified result. I want to do it automatically without writing any macros as excel does. I may do it to create an excel macro, but I don't want to.
Or how to keep data into R-Excel in active cell, so R may take the current value of every variable for every run/execution of R-commands.
Can anyone tell me the solution?

RApply should do what you want.

Related

Import only specific cells from Excel to R by hard coding

I have around 100 equal .xls files containing 10 sheets each, with very messy data, here is a thought example of one sheet:
I want to add everything together in one R dataframe/tibble.
I don't know the right approach here, but I believe that I can hard code this within readxl::read.xls. It should look like this
I would like if somebody could show a short code of how to pick a cell to be the column name by its position and the data belonging to that column, also by its position/range.
Afterwards, I will find a way to loop this to all sheets within all files, or better: If I can specify the needed code for a certain sheet name within the read.xls function. Then i only have to loop on all the files.
Thanks and let me know if you need some more information on this.

How to get R to use a certain dataset for multiple commands without usin attach() or appending data="" to every command

So I'm trying to manipulate a simple Qualtrics CSV, and I want to use colSums on certain columns of data, given a certain filter.
For example: within the .csv file called data, I want to get the sum of a few columns, and print them with certain labels (say choice1, choice2 etc). That is easy enough by itself:
firstqn<-data.frame(choice1=data$Q7_2,choice2=data$Q7_3,choice3=data$Q7_4);
secondqn<-data.frame(choice1=data$Q8_6,choice2=data$Q8_7,choice3=data$Q8_8)
print colSums(firstqn); print colSums(secondqn)
The problem comes when I want to repeat the above steps with different filters, - say, only the rows where gender==2.
The only way I know how is to create a new dataset data2 and replace data$ with data2$ in every line of the above code, such as:
data2<-(data[data$Q2==2,])
firstqn<-data.frame(choice1=data2$Q7_2,choice2=data2$Q7_3,choice3=data2$Q7_4);
however i have 6 choices for each of 5 questions and am planning to apply about 5-10 different filters, and I don't relish the thought of copy/pasting data2 and `data3' etc hundreds of times.
So my question is: Is there any way of getting R to reference data by default without using data$ in front of every variable name?
I can probably use attach() to achieve this, but i really don't want to:
data2<-(data[data$Q2==2,])
attach(data2)
firstqn<-data.frame(choice1=Q7_2,choice2=Q7_3,choice3=Q7_4);
detach(data2)
is there a command like attach() that would allow me to avoid using data$ in front of every variable, for a specified amount of code? Then whenever I wanted to create a new filter, I could just copy/paste the same code and change the first command (defining a new dataset).
I guess I'm looking for some command like with(data2, *insert multiple commands here*)
Alternatively, if anyone has a better way to do the above in an entirely different way please enlighten me - i'm not very proficient at R (yet).

Paraview : How into plot over line data selected, just save this data?

I want just save one data over line in Paraview. I make :
Load data
Cell Data To point Data
Plot data over line
I select my variable
But When I save data in the format .csv, I would like to save only the values that I select. But save.data writes every variable 14 of which I don't want. Is there a way to save only selected values?
Apply a filter such as Pass Arrays filter to remove the arrays you're not interested in. Pass Arrays filter was improved for ParaView 4.2. If you're going to use it, I'd suggest using ParaView 4.2 to avoid some annoyances with the filter.
I fine one solution, when I load data, I just load data that I want.

How, in R, do I access numbered data sets with the loop variable?

Can someone please tell me how, in R, I can access numbered data sets with the loop variable?
So, if I have a long list of files in each of which I need to find all the places where a particular value is in the second column and take the corresponding value in the same row in the third column and list these all in one file, how might I do this? The files are named by the title of the folder, date, and time, respectively, in this fashion, "name_0619_0123". There are the same number of files per each day, and they are at the times every day. Therefore if there is a command that can somehow let me access a file in such a way that I can have a variable (dependent on the loop counting variable) in the string that I give for the file name in the command, I can access a different file per each loop iterations.
Any and all ideas please
Also, if there is a more appropriate place for me to ask this question, please let me know.
There are probably lots of ways to do this in R:
You can use a command line script (see the R documentation).
i.e.
R CMD BATCH "--args arg1 arg2" foo.R &
Where foo.R is your R script and the args can be the loop varaibles you are interested in.
Another way to do this is to use regular expressions to parse out information from your file names.
If you provide a more concrete example I'll be able to show you some more specific code.
Here are some guidelines if you can glob those files you need to process either with a pattern or picking up all of them.
You may generate a list of files with list.files, read them in one shot with lapply, read.csv, and fetch what you need into a data.frame with a single row. Then, using do.call, rbind, and your list of data.frames, you can combine everything into a single data.frame without even writing for explicitly.

phpexcel calculate formulas before saving sheet

If I save a phpexcel document in Excel5 format that contains values only, people that reference the document can open and close it without issue.
But if I put some formulas in cells, I have two undesired outcomes.
Just before saving the document I set the column widths based on the contents of the columns. Since the formulas have not been calcuated, the columns appear to be only as large as the largest single value in the column so the width is set too narrow. Once the =sum() formulas are calculated after being opened in excel, the contents overflow the cell width and display as a string of ###.
The second effect is that when the total is calculated by excel, the book is marked as modified by excel. When the user attempts to exit the book, they are prompted to see if they want to save their changes. This is disconcerting because in their mind they have not changed anything and annoying because it is an interuption that they really don't want to contend with.
I have been searching the documentation. I found a reference to $objWriter->setPreCalculateFormulas(true) but it does not help with either issue.
If a column is set to AutoSize, PHPExcel attempts to calculate the column width based on the calculated value of the column (so on the result of your SUM() formula), and any additional characters added by format masks such as thousand separators. By default, this is an estimated width: a more accurate calculation method is available, based on using GD, but this is a much bigger overhead, so it is turned off by default. You can enable the more accurate calculation using
PHPExcel_Shared_Font::setAutoSizeMethod(PHPExcel_Shared_Font::AUTOSIZE_METHOD_EXACT);
If a worksheet contains formulae, then some versions of MS Excel files hold additional information detailing the calculation tree: data that is not saved by PHPExcel (because calculating the tree structure is a big overhead). You don't indicate which format you are using to save your workbooks, or which version of MS Excel you're using to open them; but this is the normal explanation for any prompting to save changes when a PHPExcel-generated file is opened in MS Excel.
It works for me if you paste it just before saving the file, like this:
$objWriter->setPreCalculateFormulas(true);
$objWriter -> save("file.xlsx");

Resources