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

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

  • Curiosity
  • Know what is the algorithm used in the numerical computations
  • 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.

    PS (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)


    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).


    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...
    

    .libPaths() should tell you all of your current library locations. It's possible to have more than one installation of a package if there are two libraries but only the one that is in the first library will be used. Unless you offer the code and the exact error message, it's not likely that anyone will be able to offer better advice.

    链接地址: http://www.djcxy.com/p/25038.html

    上一篇: 在R中绘制时数值矩阵范围误差

    下一篇: PC上的.R脚本文件在哪里?