Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the .R script file located on the PC?

Tags:

r

I want to find the location of the script .R files which are used for computation in R.

I know that by typing the object function, I will get the code which is running and then I can copy and edit and save it as a new script file and use that.

The reason for asking to find the foo.R file is

  1. Curiosity
  2. Know what is the algorithm used in the numerical computations
  3. More immedietly, the function from stats package I am using, is running results for two of the arguments and not the others and have to figure out how to make it work. Error shown by R implies that there might be some modification required in the script file.

I am looking for a more general answer, if its possible.

Edit: As per the comments so far, here is the code to compute spectrum of a time series using autoregressive methods. The data input is a univariate series.

x = ts(data)
spec.ar(x, method = "yule-walker")    1
spec.ar(x, method = "burg")        2

command 1 is running ok. command 2 gives the following error.

Error in ar.burg.default(x, aic = aic, order.max = order.max, na.action = na.action,  : 
  Burg's algorithm only implemented for univariate series

I did try specify all the arguments correctly like na.action=na.fail, order.max = NULL etc but the message is the same. Kindly suggest possible solutions.

P.S. (This question is posted after searching the library folder where R is installed and zip files which come with packages, manuals, and opening .rdb, .rdx files)

like image 862
Anusha Avatar asked Feb 21 '12 21:02

Anusha


People also ask

How do I view a .R file?

The R and RStudio programs are typically used to open R files since they provide helpful IDE tools. You can also use a plain text editor to view the contents of an R script.

Where are R scripts stored?

Press the Save button and your script is saved to your working folder. Notice that the name in the file tab at the top of the Script Editor panel now shows your saved script file name.

How do I find an Rscript file in a typical file system?

Location of the R Script FileThe R script file is located in the R script's directory, as specified in the _RScriptFile parameter for the R script's metric in MicroStrategy.

How do I create a .R file?

There are two ways to create an R file in R studio: You can click on the File tab, from there when you click it will give a drop-down menu, where you can select the new file and then R script, so that, you will get a new file open.


2 Answers

See FAQ 7.40 How do I access the source code for a function?

In most cases, typing the name of the function will print its source code. However, code is sometimes hidden in a namespace, or compiled. For a complete overview on how to access source code, see Uwe Ligges (2006), “Help Desk: Accessing the sources”, R News, 6/4, 43–45 (http://cran.r-project.org/doc/Rnews/Rnews_2006-4.pdf).

like image 58
mdsumner Avatar answered Oct 26 '22 05:10

mdsumner


When R installs a package, it evaluates all the ".R" source files and re-saves them into a binary format for faster loading. Therefore you typically cannot easily find the source file.

As has been suggested elsewhere, you can simply type the function name and see the source code, or download the source package and find the source there.

library(plyr)
ddply # prints the source for ddply

# See the content of the R directory for plyr,
# but it's only binary files:
dir(file.path(find.package("plyr"), "R"))
# [1] "plyr"     "plyr.rdb" "plyr.rdx"

# Get the source for the package:
download.packages("plyr", "~", type="source")

# ...then unpack and inspect the R directory...
like image 32
Tommy Avatar answered Oct 26 '22 04:10

Tommy