Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
2701 views
1
2
.ess_funargs <- function(funname) {
3
if(.ess.Rversion > '2.14.1') {
4
comp <- compiler::enableJIT(0)
5
olderr <- getOption('error')
6
options(error=NULL)
7
on.exit({
8
compiler::enableJIT(comp)
9
options(error = olderr)
10
})
11
}
12
## don't remove; really need eval(parse( here!!
13
fun <- tryCatch(eval(parse(text=funname)),
14
error=function(e) NULL) ## also works for special objects containing @:$ etc
15
if(is.function(fun)) {
16
special <- grepl('[:$@[]', funname)
17
args <- if(!special){
18
fundef <- paste(funname, '.default',sep='')
19
do.call('argsAnywhere', list(fundef))
20
}
21
22
if(is.null(args))
23
args <- args(fun)
24
if(is.null(args))
25
args <- do.call('argsAnywhere', list(funname))
26
27
fmls <- formals(args)
28
fmls_names <- names(fmls)
29
fmls <- gsub('\"', '\\\"',
30
gsub("\\", "\\\\", as.character(fmls),fixed = TRUE),
31
fixed=TRUE)
32
args_alist <-
33
sprintf("'(%s)",
34
paste("(\"", fmls_names, "\" . \"", fmls, "\")",
35
sep = '', collapse = ' '))
36
allargs <-
37
if(special) fmls_names
38
else tryCatch(gsub('=', '', utils:::functionArgs(funname, ''), fixed = TRUE),
39
error=function(e) NULL)
40
allargs <- sprintf("'(\"%s\")",
41
paste(allargs, collapse = '\" "'))
42
envname <- environmentName(environment(fun))
43
if(envname == "R_GlobalEnv") envname <- ""
44
cat(sprintf('(list \"%s\" %s %s)\n',
45
envname, args_alist, allargs))
46
}
47
}
48
49
.ess_get_completions <- function(string, end){
50
if(.ess.Rversion > '2.14.1'){
51
comp <- compiler::enableJIT(0)
52
olderr <- getOption('error')
53
options(error=NULL)
54
on.exit({options(error = olderr)
55
compiler::enableJIT(comp)})
56
}
57
utils:::.assignLinebuffer(string)
58
utils:::.assignEnd(end)
59
utils:::.guessTokenFromLine()
60
utils:::.completeToken()
61
c(get('token', envir=utils:::.CompletionEnv),
62
utils:::.retrieveCompletions())
63
}
64
65