Gundala Viswanath
2008-Jul-16 07:28 UTC
[R] Howto view function's source code of an installed package
Hi, Is there a way I can view the functions source code of a package I installed in my PC. For example I downloaded the great "mixtools" package. I want to see the source code of one of its function "normalmixEM" Is there a way to do it? Presumably from R command prompt? I tried to take a look at the zip file, but somehow I can't seem to find the file on which I can find the source code. Please advice. - Gundala Viswanath Jakarta - Indonesia
Paul Hiemstra
2008-Jul-16 08:12 UTC
[R] Howto view function's source code of an installed package
Gundala Viswanath wrote:> Hi, > > Is there a way I can view the functions source code of a > package I installed in my PC. > > For example I downloaded the great "mixtools" package. > I want to see the source code of one of its function "normalmixEM" > > Is there a way to do it? Presumably from R command prompt? > > I tried to take a look at the zip file, but somehow I can't seem > to find the file on which I can find the source code. Please advice. > > - Gundala Viswanath > Jakarta - Indonesia > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >Hi, You can see the R-source code of a function if you give the command without the brackets. For example: > sort function (x, decreasing = FALSE, ...) { if (!is.logical(decreasing) || length(decreasing) != 1) stop("'decreasing' must be a length-1 logical vector.\nDid you intend to set 'partial'?") UseMethod("sort") } <environment: namespace:base> Another option is to download the .tar.gz source package from CRAN, unpack it and the R source code is available in the "R" subdirectory. cheers, Paul -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +31302535773 Fax: +31302531145 http://intamap.geo.uu.nl/~paul
Mark Miller
2010-Sep-28 19:10 UTC
[R] Howto view function's source code of an installed package
I justed wanted to provide a description of how I was able to view source code of a function. First download the Program R package containing the function. Specifically, download the file that ends in "tar.gz". This is a compressed file. Expand the compressed file using, for example, "WinZip". Next open the uncompressed file that ends in ".tar". I was able to open that file with the free software "7-Zip" available on the internet. After installing that software I clicked on the file "7zFM.exe" and navigated to the directory containing the ".tar" file. You can extract the contents of that ".tar" file into a new folder. The contents consist of R files showing the source code for the functions in the R package. These R files can be opened with a text editor. Hopefully, it is okay to mention other software here by name. I have used the above method twice in the last few months to view source code for functions. In both instances I needed a substantial amount of time to figure out how to do it. This post might help others and perhaps will help myself in the future. Mark W. Miller Gainesville, Florida -- View this message in context: http://r.789695.n4.nabble.com/Howto-view-function-s-source-code-of-an-installed-package-tp831711p2717744.html Sent from the R help mailing list archive at Nabble.com.