source code for autocompletion in R run in terminal - r

I would like to study the autocomplete code of R, when R is run in a terminal. For example, if you run R from the terminal and type lm( and then tab, R will give you the arguments of lm.
Dirk's answer here suggests that autocompletion of R is supported by the codetools package which is in base R:
Is it possible to get code completion for R in Emacs ESS similar to what is available in Rstudio?
However, I can't find where in that package it adds support for autocomplete. I grepped for 'completion' and came up empty.

The completion code is actually in the base instalation in the utils package. You can view everything associated with it (for the devel version) on R's SVN server:
http://svn.r-project.org/R/trunk/src/library/utils/R/completion.R
This code should be read in conjunction with ?completion.

Related

Source code of the function `grDevices:::C_col2rgb`?

How can I find the source C code of the function grDevices:::C_col2rgb?
I've been led to this function after benchmarking (using R pkg profvis) some RGL functions, namely rgl:::rgl.quads and functions called therein. The corresponding R function that wraps C_col2rgb is col2rgb from grDevices. I'm interested in looking at the source of C_col2rgb to see whether I could make a faster version.
And, in general, when you encounter a C function being used in R code, is there an expedite way of finding its source code?
Many thanks!
Normally when you want to view the source code of an R function, you can just type its name in the console and press enter. However, when that function is written in another language, such as C, and exposed to R, you will just eventually see (something like)
.Call(C_col2rgb, col, alpha)
where R calls the compiled code. To see the source code of such functions, you actually have to look at the package source code. The function you are talking about is in the grDevices package, which is part of what is often called "base R" (not (necessarily) to be confused with the R package base) -- the package ships with all R installations.
There is an R source code mirror on GitHub at https://github.com/wch/r-source that I like to consult if I need to look at R's source code. The code for the grDevices package is there at https://github.com/wch/r-source/tree/trunk/src/library/grDevices.
As I mentioned in the comments, you can find the code for C_col2rgb() at r-source/src/library/grDevices/src/colors.c. However, there it looks like it's just called col2rgb(). Is it really the same?
Yes. If you consult Writing R Extensions, Section 1.5.4, you see that
A NAMESPACE file can contain one or more useDynLib directives which allows shared objects that need to be loaded.... Using argument .fixes allows an automatic prefix to be added to the registered symbols, which can be useful when working with an existing package. For example, package KernSmooth has
    useDynLib(KernSmooth, .registration = TRUE, .fixes = "F_")
which makes the R variables corresponding to the Fortran symbols F_bkde and so on, and so avoid clashes with R code in the namespace.
We can see in the NAMESPACE file for grDevices
useDynLib(grDevices, .registration = TRUE, .fixes = "C_")
So, the C functions that are made available from this package will all be prefixed with C_ even though they aren't in the C source code. This lets you call both the R and the C functions col2rgb without causing any problems.

Faster way of generating R package documentation (i.e. pdf manual) in roxygen2?

For a package made with roxygen2, documentaiton can be generated with
R CMD check package_name
Is there a faster way to generate the package manual (pdf)?
Note: it must work for roxygen2-made packages. I tried (this method, but it doesn't appear to work for a roxygen2-made package)

Emacs: What does it mean to 'put a caret on a word'?

I am trying to utilize the ess-R-data-view.el package to view data frames in R. The scant documentation contains the following cryptic passage:
Put caret on a word that indicate dataframe or matrix, and M-x
ess-R-dv-ctable or M-x ess-R-dv-pprint. So, it popups other buffer
containing table.
I have the following packages installed:
ctable
ess
ess-R-data-view
popup
Additionally, I have R installed and have been able to use ESS without any problems. I am running GNU Emacs 24.5.1 (i686-pc-mingw32) (that is, Emacs on Windows). I do not have Cygwin installed at this time.
Here is a link to the ess-R-data-view.el github:
https://github.com/myuhe/ess-R-data-view.el/blob/master/README.org

R View() function does not show data frame

I am using R (Version 3.1.2) with RStudio (Version 0.98.1091) on a Linux Ubuntu machine. I have a csv file loaded in variable:
rr <- read.csv("/home/user/seconds.csv")
When I call View(rr) I expect to open a new tab and display the CSV data in the rr variable. However, it opens a new tab called rr and it displays the following message.
/content?title=rr&file=94af460bd6644d3aaac734d585046c4f.htm not found
The View function is from package 'utils' which is not supported by the version of R you are using.
I am on a x86_64-w64-mingw32 system with R version 3.4.1, but I want to share a simple solution to get View working again in my case.
Following the step 4 of advice from Tian on Rstudio support (https://support.rstudio.com/hc/en-us/community/posts/115007743908-The-Rstudio-view-not-work-just-blank-), I entered:
install.packages("dplyr", dependencies = TRUE)
Now it works.

R syntax highlighting in Terminal

Can we get syntax highlighting for R in the Terminal?
I've finally found a library that meets my needs.
Now I'm much happier with my coding environment.
colorout is an R package that colorizes R output when running in a terminal emulator.The package cannot be on CRAN because it changes code already loaded by R and this is prohibited by the CRAN Repository Policy. The package replaces the functions that output results and messages to R Console, and this is necessary because we cannot colorize the output without replacing these functions. To install it, do the following in R:
install.packages("devtools")
devtools::install_github("jalvesaq/colorout")
library("colorout")
# do something
Use something like ess on emacs or RStudio for syntax highlighting for R instead of expecting it to work in the terminal.
Another option now would be to use radian instead of the default R prompt.
As hd1 indicated, this is not an R question. You're asking the OSX Terminal.app to do something it's not capable of. A quick look around Google (happy Zamboni birthday!) shows Vim syntax Highlighting for highlighting within vim , or https://superuser.com/questions/72057/terminal-emulator-with-custom-color-palette , but dunno if these will run under Darwin.
EDIT: I can't stay away from the search :-) . So check out these threads: https://superuser.com/questions/400360/syntax-highlighting-in-terminal-mac-os-x , http://forums.macrumors.com/showthread.php?t=412609 , and a recommendation to install zsh , https://apple.stackexchange.com/questions/12161/os-x-terminal-must-have-utilities

Resources