Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I'm new to R and I'm wondering if R has something similar to SAS program where it can store the codes? I need to run the analysis on my data set (update monthly) every month. In SAS, I can just run the program and it will give me the results. I'd like to know if R has something similar to that? Thank you so much!
[Update] Thanks for the answers. R script is what I'm looking for!
Are you just talking about running an R script?? If you have a text file called codefile.R containing R code, then from within an interactive R session source("codefile.R") will run it. Or you can use R CMD BATCH codefile.R from a command line/shell/terminal.
update: Dirk Eddelbuettel points out that Rscript or the littler package are recommended over R CMD BATCH ...
Yes. Just like you can create SAS programs in the enhanced editor, you can create R scripts in R. This process is even easier, in my opinion, when you write your R scripts using the tools that come with R Studio.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
As I'm dealing with a huge dataset I had to split my data into different buckets. Thus, I want to save some interim results in a csv to recall it later. However, my datafile contains some columns with lists, which according to R can not be exported (see snapshot). Do you guys know a simple way for a R newbie to make this work?
Thank you so much!
I guess the best way to solve your problem is switching to a more apropriate file format. I recomend using write_rds() from the readr package, which creates .rds files. The files you create with readr::write_rds('your_file_path') can be read in with readr::read_rds('your_file_path').
The base R functions are saveRDS() and readRDS() and the functions mentioned earlier form the readr are just wrappers with some convience features.
Just right click, then choose new csv to the folder where you want to save your work. Then set the separator of the csv to a comma.
Input all data in column form. You can later make it a matrix in your R program.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Suppose I have VBA macro in Excel which does some calculation. And I would like to do a part of this calculation in R, but in program mode. Say, at some moment Excel macro has a vector and it needs to find its mean by mean function in R. How can I call R from VBA, transmit a vector to R, initiate the calculation in R and get back the result in VBA? Thanks.
There is a plugin RExcel, but I found quite horrible to use it (and you kinda have to pay for it).
The easiest and most general but hacky way to perform your interaction is the following:
1) Save your array/matrix/vector in csv in a folder
2) write your R code in a file that read the csv and write the result in csv
3) Call the R script from VBA with the VBA Shell function (Rscript scriptName.R)
4) Import the result back to excel/VBA.
This method has the advantage that you are separating the computational logic with the formatting from VBA.
You could also call the R code directly within VBA with -e option from R but this is strongly unadvised.
Hope it helps!
BTW: it works with all the other program (Python/LaTeX/Matlab).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm new in R
can you give me some example code I need use to read and write tiff image in R
or just list the step
Thanks
Google is going to be your friend when learning R. It's old enough that everything is out there. :)
Tiff Package
To install this, you might want to try :
install.packages("tiff")
But if you want to use it put this at the top of each script
library("tiff")
To read and write I suggest :
writeTIFF(yourdatahere, getwd())
You don't assign a name to it because you are just outputting data at this point. Here is getting a TIFF.
TiffObject <- readTIFF(yourfile)
Make sure your file is in your working directory. You can set your working directory by doing :
setwd(path)
If you need anything else, just comment and I shall help.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have an R dataset (an .Rdata file) that I need to convert to either SAS (.sas7bdat or .xpt) or SPSS (.sav or .por). How can I import this dataset into SAS or SPSS?
If you want to use this in SPSS, consider using the STATS_GETR extension command. It can read R workspace or data files and map appropriate elements directly to an SPSS dataset. This extension command is available from the SPSS Community (www.ibm.com/developerworks/spssdevcentral) website or, for Statistics 22, it can be installed via the Utilities menu.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Right now I wrote some script that could analyze the daily dumped file from Hadoop. What I want is to let my R script runs daily at 4AM after new data becomes available. Is there any script from R side or OS side could make this happen automatically?
What I can think of is to leave have another R script idling and keep checking system time to decide to call my script to run, but is this too much? I prefer to have R closed unless necessarily.
OK, I see the answer. Does anyone have experience commenting on the stability between R and Python, in terms of running large scale data processing task.
http://www.thegeekstuff.com/2009/06/15-practical-crontab-examples/
-or better yet-
http://tgmstat.wordpress.com/2013/09/11/schedule-rscript-with-cron/
Those websites should be all you need to get it going. Assuming you are using linux.
you can use this code
Sys.time()
for(period in 1:365){
{
your code here
}
newdate=as.POSIXct("2014-11-14 04:00:00 GMT")+24*60*60*period
Sys.sleep( newdate - Sys.time() )
}