117 |
118 |
119 | HFS2
120 |
121 | sleep 0.05
122 |
--------------------------------------------------------------------------------
/Support/bin/askRhelperDaemon.sh:
--------------------------------------------------------------------------------
1 |
2 | #dispose all frozen ProgressDialogs first
3 | {
4 | while [ 1 ]
5 | do
6 | res=$("$DIALOG" -x `"$DIALOG" -l 2>/dev/null| grep Rdaemon | cut -d " " -f 1` 2>/dev/null)
7 | [[ ${#res} -eq 0 ]] && break
8 | done
9 | } &
10 |
11 |
12 | "$TM_BUNDLE_SUPPORT"/bin/startRhelperDaemon.sh &> /dev/null
13 | echo "$1" > /tmp/textmate_Rhelper_in
14 | sleep 0.01
15 | SAFECNT=0
16 | while [ 1 ]
17 | do
18 | SAFECNT=$(($SAFECNT+1))
19 | if [ $SAFECNT -gt 5000 ]; then
20 | echo -en "No RESULT from R Helper server!"
21 | exit 206
22 | fi
23 | RES=$(tail -c 2 /tmp/textmate_Rhelper_console)
24 | [[ "$RES" == "> " ]] && break
25 | sleep 0.01
26 | done
27 | if [ -e /tmp/textmate_Rhelper_status ]; then
28 | SAFECNT=0
29 | sleep 0.001
30 | while [ `cat /tmp/textmate_Rhelper_status` != "READY" ]
31 | do
32 | SAFECNT=$(($SAFECNT+1))
33 | if [ $SAFECNT -gt 1000 ]; then
34 | echo -en "No RESULT from R Helper server!"
35 | exit 206
36 | fi
37 | sleep 0.01
38 | done
39 | fi
40 |
41 |
42 |
--------------------------------------------------------------------------------
/Support/bin/auto_show_func_usage.sh:
--------------------------------------------------------------------------------
1 |
2 | export WORD=$(ruby18 -- <<-SCR1
3 | print ENV['TM_CURRENT_LINE'][0...ENV['TM_LINE_INDEX'].to_i].gsub!(/ *$/, "").match(/[\w.:]*$/).to_s
4 | SCR1
5 | )
6 |
7 |
8 | WORDORG="$WORD"
9 | PKG=""
10 | if [ `echo "$WORD" | grep -Fc ':'` -gt 0 ]; then
11 | PKG=",package='${WORD%%:*}'"
12 | fi
13 | WORD="${WORD##*:}"
14 |
15 | #check whether WORD is defined otherwise quit
16 | [[ -z "$WORD" ]] && exit 200
17 |
18 | TEXT=$(cat)
19 |
20 | RhelperAnswer="/tmp/textmate_Rhelper_out"
21 |
22 | # Rdaemon
23 | RPID=$(ps aw | grep '[0-9] /.*TMRdaemon' | awk '{print $1;}' )
24 | RD=$(echo -n "$TM_SCOPE" | grep -c -F 'source.rd.console')
25 | if [ ! -z "$RPID" -a "$RD" -gt 0 ]; then
26 | RDHOME="$HOME/Library/Application Support/Rdaemon"
27 | if [ "$TM_RdaemonRAMDRIVE" == "1" ]; then
28 | RDRAMDISK="/tmp/TMRramdisk1"
29 | else
30 | RDRAMDISK="$RDHOME"
31 | fi
32 | [[ -e "$RDRAMDISK"/r_tmp ]] && rm "$RDRAMDISK"/r_tmp
33 |
34 | # execute "args()" in Rdaemon
35 | TASK="@|sink('$RDRAMDISK/r_tmp');args($WORDORG)"
36 | echo "$TASK" > "$RDHOME"/r_in
37 | echo "@|sink(file=NULL)" > "$RDHOME"/r_in
38 | while [ 1 ]
39 | do
40 | RES=$(tail -c 2 "$RDRAMDISK"/r_out)
41 | [[ "$RES" == "> " ]] && break
42 | [[ "$RES" == ": " ]] && break
43 | [[ "$RES" == "+ " ]] && break
44 | sleep 0.03
45 | done
46 | sleep 0.001
47 | RES=$(cat "$RDRAMDISK"/r_tmp | sed 's/NULL$//;')
48 | [[ "$RES" == "NULL" ]] && RES=""
49 | # "args()" did find something
50 | if [ ! -z "$RES" ]; then
51 | OUT=$(echo -en "$WORD${RES:9}" | perl -e 'undef($/);$a=<>;$a=~s/"\t"/"\\t"/sg;$a=~s/"\n"/"\\n"/sg;print $a')
52 | rm -f "$RDRAMDISK"/r_tmp
53 | TASK="@|sink('$RDRAMDISK/r_tmp');cat(gsub('.*?/library/(.*?)/.*','\\\\1',as.vector(help('$WORD',try.all.packages=F)),perl=T),sep='\n')"
54 | echo "$TASK" > "$RDHOME"/r_in
55 | TASK="@|sink(file=NULL)"
56 | echo "$TASK" > "$RDHOME"/r_in
57 | while [ 1 ]
58 | do
59 | RES=$(tail -c 2 "$RDRAMDISK"/r_out)
60 | [[ "$RES" == "> " ]] && break
61 | [[ "$RES" == ": " ]] && break
62 | [[ "$RES" == "+ " ]] && break
63 | sleep 0.03
64 | done
65 | sleep 0.001
66 | LIB=$(cat "$RDRAMDISK"/r_tmp)
67 | if [ -z "$LIB" ]; then
68 | echo -n "$OUT"
69 | echo -en "\n• local"
70 | exit 206
71 | fi
72 | CNT=$(echo "$LIB" | wc -l)
73 | if [ $CNT -eq 1 ]; then
74 | echo -n "$OUT"
75 | echo -en "\n•• library: $LIB"
76 | exit 206
77 | fi
78 | # "args()" didn't find anything ergo library isn't yet loaded
79 | else
80 | "$TM_BUNDLE_SUPPORT"/bin/askRhelperDaemon.sh "@getHelpURL('$WORD'$PKG)"
81 | FILE=$(cat "$RhelperAnswer")
82 | if [ ! -z "$FILE" -a "$FILE" != "NA" ]; then
83 | exec<"$RhelperAnswer"
84 | while read i
85 | do
86 | if [ "${i:0:1}" = "/" ]; then
87 | RES=$(cat "$i")
88 | else
89 | RES=$(curl -gsS "$i")
90 | fi
91 | echo -n "$RES" | "$TM_BUNDLE_SUPPORT/bin/parseHTMLForUsage.sh" "$WORD" 0
92 | LIB=$(echo "$i" | perl -pe 's!.*?/library/(.*?)/.*!$1!')
93 | TASK="@|sink('$RDRAMDISK/r_tmp')"
94 | echo "$TASK" > "$RDHOME"/r_in
95 | TASK="@|cat(sum((.packages()) %in% \"$LIB\"),sep='')"
96 | echo "$TASK" > "$RDHOME"/r_in
97 | TASK="@|sink(file=NULL)"
98 | echo "$TASK" > "$RDHOME"/r_in
99 | while [ 1 ]
100 | do
101 | RES=$(tail -c 2 "$RDRAMDISK"/r_out)
102 | [[ "$RES" == "> " ]] && break
103 | [[ "$RES" == ": " ]] && break
104 | [[ "$RES" == "+ " ]] && break
105 | sleep 0.02
106 | done
107 | sleep 0.001
108 | RES=$(cat "$RDRAMDISK"/r_tmp)
109 | if [ ! -z "$RES" -a "$RES" == "1" ]; then
110 | echo -en "\n•• library: $LIB"
111 | else
112 | echo -en "\n• library “${LIB}” not loaded [press CTRL+SHIFT+L]"
113 | fi
114 | echo
115 | done
116 | exit 206
117 | else
118 | exit 200
119 | fi
120 | fi
121 | fi
122 |
123 | # R script
124 | "$TM_BUNDLE_SUPPORT"/bin/askRhelperDaemon.sh "@getHelpURL('$WORD'$PKG)"
125 | FILE=$(cat "$RhelperAnswer")
126 | if [ ! -z "$FILE" -a "$FILE" != "NA" ]; then
127 | exec<"$RhelperAnswer"
128 | while read i
129 | do
130 | if [ "${i:0:1}" = "/" ]; then
131 | RES=$(cat "$i")
132 | else
133 | RES=$(curl -gsS "$i")
134 | fi
135 | # "$TM_BUNDLE_SUPPORT"/bin/askRhelperDaemon.sh "@getPackageFor('$WORD')"
136 | # LIB=$(cat "$RhelperAnswer")
137 | LIB=$(echo "$i" | perl -pe 's!.*?/library/(.*?)/.*!$1!')
138 | RES=$(echo -en "$RES" | "$TM_BUNDLE_SUPPORT/bin/parseHTMLForUsage.sh" "$WORD" 0)
139 | if [ ! -z "$RES" -a "${RES:0:1}" == "${WORD:0:1}" ]; then
140 | echo -n "$RES"
141 | echo -en "\n•• library: $LIB\n"
142 | fi
143 | done
144 | exit 206
145 | else
146 | [[ `echo -n "$TM_SCOPE" | grep -c -F 'text.tex.latex.rdaemon'` -gt 0 ]] && exit 200
147 | # Parse R script for functions
148 | OUT=$(echo -en "$TEXT" | "$TM_BUNDLE_SUPPORT/bin/parseDocForFunctions.sh" "$WORD")
149 | [[ -z "$OUT" ]] && exit 200
150 | echo -n "$WORD$OUT
151 | • local"
152 | exit 206
153 | fi
154 |
--------------------------------------------------------------------------------
/Support/bin/initCommandArgsDir.sh:
--------------------------------------------------------------------------------
1 | WDIR="$HOME/Library/Application Support/TextMate/R/help"
2 |
3 | if [ ! -e "$WDIR/command_args" ]; then
4 | mkdir -p "$WDIR/command_args"
5 | cp -R "$TM_BUNDLE_SUPPORT"/lib/command_args "$WDIR"
6 | fi
--------------------------------------------------------------------------------
/Support/bin/insert_command_template.rb:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby18
2 | require File.join(ENV['TM_SUPPORT_PATH'], "lib/exit_codes.rb")
3 | require File.join(ENV['TM_SUPPORT_PATH'], "lib/ui.rb")
4 | require File.join(ENV['TM_SUPPORT_PATH'], 'lib/current_word.rb')
5 |
6 | require File.join(ENV['TM_BUNDLE_SUPPORT'], 'lib/popen3.rb')
7 |
8 | word = Word.current_word('\w\.')
9 |
10 | stdin, stdout, stderr = popen3("R", "--vanilla", "--no-readline", "--slave", "--encoding=UTF-8")
11 |
12 | stdin.write(File.read(File.join(ENV['TM_BUNDLE_SUPPORT'], 'getSig.R')))
13 |
14 | wordEsc = word.gsub("\\|'", "\\\\\\0")
15 | wordReg = Regexp.escape(word).gsub("\\|'", "\\\\\\0")
16 | stdin.puts("cat(paste(getSig(if ('#{wordEsc}' %in% (ary <- sort(apropos('^#{wordReg}', mode='function')))) '#{wordEsc}' else ary), collapse='\\n'))")
17 | stdin.close
18 |
19 | text = stdout.read()
20 |
21 | TextMate.exit_show_tool_tip("No function signature known for `#{word}'") if text.empty?
22 |
23 | functions = text.split("\n")
24 | if functions.size == 1
25 | function = functions.first
26 | else
27 | # term = TextMate::UI.request_item :title => "Snippet for Command", :prompt => "There were more than one matching commands found", :items => functions.collect { |f| f[0...f.index("(")] }
28 | idx = TextMate::UI.menu functions.collect { |f| f[0...f.index("(")] }
29 | TextMate.exit_discard if idx.nil?
30 | function = functions[idx]
31 | # function = functions.find("") { |f| f[0..term.length] == term + "(" }
32 | end
33 |
34 | TextMate.exit_discard if function.empty?
35 |
36 | if ENV['TM_SELECTED_TEXT'].nil? or ENV['TM_SELECTED_TEXT'].empty?
37 | # we didn't use selected text but instead pulled the word from the line
38 | # so lets only insert everything after the term
39 | print function[word.length..-1]
40 | NameError
41 | else
42 | print function
43 | end
44 |
--------------------------------------------------------------------------------
/Support/bin/insert_function_param.sh:
--------------------------------------------------------------------------------
1 |
2 | [[ -n "$TM_SELECTED_TEXT" ]] && echo "Please unselect first." && exit 206
3 |
4 | #look for nested commands and set WORD to the current one
5 | WORD=$(perl -e '
6 | $line=$ENV{"TM_CURRENT_LINE"};
7 | $col=$ENV{"TM_LINE_INDEX"};
8 | $line=substr($line,0,$col);
9 | $line=~s/ //g;
10 | @arr=split(//,$line);$c=0;
11 | for($i=$#arr;$i>-1;$i--){$c-- if($arr[$i] eq ")");$c++ if($arr[$i] eq "(");last if $c>0;}
12 | substr($line,0,$i)=~m/([\w\.:]+)$/;
13 | print $1 if defined($1);
14 | ')
15 |
16 | PKG=""
17 | if [ `echo "$WORD" | grep -Fc ':'` -gt 0 ]; then
18 | PKG=",package='${WORD%%:*}'"
19 | fi
20 | WORD="${WORD##*:}"
21 | OUT=""
22 | #check whether WORD is defined otherwise quit
23 | [[ -z "$WORD" ]] && echo "No keyword found" && exit 206
24 |
25 | #check for user-defined parameter list
26 | "$TM_BUNDLE_SUPPORT"/bin/initCommandArgsDir.sh
27 | if [ -e "$HOME/Library/Application Support/TextMate/R/help/command_args/$WORD" ]; then
28 | RES=$(cat "$HOME/Library/Application Support/TextMate/R/help/command_args/$WORD")
29 | else
30 | # Rdaemon
31 | RPID=$(ps aw | grep '[0-9] /.*TMRdaemon' | awk '{print $1;}' )
32 | RD=$(echo -n "$TM_SCOPE" | grep -c -F 'source.rd.console')
33 | if [ ! -z "$RPID" -a "$RD" -gt 0 ]; then
34 | RDHOME="$HOME/Library/Application Support/Rdaemon"
35 | if [ "$TM_RdaemonRAMDRIVE" == "1" ]; then
36 | RDRAMDISK="/tmp/TMRramdisk1"
37 | else
38 | RDRAMDISK="$RDHOME"
39 | fi
40 | [[ -e "$RDRAMDISK"/r_tmp ]] && rm "$RDRAMDISK"/r_tmp
41 |
42 | # execute "args()" in Rdaemon
43 | TASK="@|sink('$RDRAMDISK/r_tmp');args($WORD)"
44 | echo "$TASK" > "$RDHOME"/r_in
45 | echo "@|sink(file=NULL)" > "$RDHOME"/r_in
46 | while [ 1 ]
47 | do
48 | RES=$(tail -c 2 "$RDRAMDISK"/r_out)
49 | [[ "$RES" == "> " ]] && break
50 | [[ "$RES" == ": " ]] && break
51 | [[ "$RES" == "+ " ]] && break
52 | sleep 0.03
53 | done
54 | sleep 0.001
55 | OUT=$(cat "$RDRAMDISK"/r_tmp | perl -e 'undef($/);$a=<>;$a=~s/NULL$//;$a=~s/^.*?\(/(/;$a=~s/"\t"/"\\t"/sg;$a=~s/"\n"/"\\n"/sg;$a=~s/\n//sg;print $a')
56 | [[ "$OUT" == "NULL" ]] && OUT=""
57 | fi
58 |
59 | if [ -z "$OUT" ]; then
60 | # Get URL for current function
61 | "$TM_BUNDLE_SUPPORT"/bin/askRhelperDaemon.sh "@getHelpURL('$WORD'$PKG)"
62 | FILE=$(cat /tmp/textmate_Rhelper_out)
63 | if [ `cat /tmp/textmate_Rhelper_out | wc -l` -gt 1 ]; then
64 | echo -e "Function '$WORD' is ambiguous.\nFound in packages:"
65 | echo "$FILE" | perl -pe 's!.*?/library/(.*?)/.*?/.*!$1!'
66 | exit 206
67 | fi
68 | if [ ! -z "$FILE" -a "$FILE" != "NA" ]; then
69 | if [ "${FILE:0:1}" = "/" ]; then
70 | RES=$(cat "$FILE")
71 | else
72 | RES=$(curl -gsS "$FILE")
73 | fi
74 | OUT=$(echo -en "$RES" | "$TM_BUNDLE_SUPPORT/bin/parseHTMLForUsage.sh" "$WORD" 1)
75 | else
76 | # Parse R script for functions
77 | OUT=$(cat | "$TM_BUNDLE_SUPPORT/bin/parseDocForFunctions.sh" "$WORD" | perl -e 'undef($/);$a=<>;$a=~s/"\t"/"\\t"/sg;$a=~s/"\n"/"\\n"/sg;$a=~s/\n//sg;print $a')
78 | # Check for errors
79 | if [ `echo -n "$OUT" | grep -F 'declaration possibly erroneous:' | wc -l` -gt 0 ]; then
80 | echo "$WORD$OUT" && exit 206
81 | fi
82 | fi
83 |
84 | if [ -z "$OUT" ]; then
85 | echo "Nothing found"
86 | exit 206
87 | fi
88 | fi
89 | # Evaluate function arguments and get a list of them
90 | "$TM_BUNDLE_SUPPORT"/bin/askRhelperDaemon.sh "for (i in names(formals(function $OUT {})->a)) {cat(i);cat(' = ');print(a[[i]])}"
91 | RES=$(cat /tmp/textmate_Rhelper_out | perl -e 'undef($/);$a=<>;$a=~s/ = \[1\] / = /g;$a=~s/\.\.\..*\n//g;$a=~s/\n +//g;print $a' )
92 |
93 | fi
94 |
95 | #if no parameter quit
96 | if [ -z "$RES" ]; then
97 | echo -n "Nothing found"
98 | exit 206
99 | fi
100 |
101 | #show all parameters as inline menu and insert the parameter as snippet (if '=' is found only the value)
102 | ruby18 -- <<-SCRIPT
103 | # 2> /dev/null
104 | require File.join(ENV["TM_SUPPORT_PATH"], "lib/exit_codes.rb")
105 | require "#{ENV["TM_SUPPORT_PATH"]}/lib/ui"
106 | word = "$WORD"
107 | text = %q[$RES]
108 | funs = text.split("\n")
109 | TextMate.exit_discard if funs.size < 1
110 |
111 | if funs.size == 1
112 | function = funs.first
113 | else
114 | funs.unshift("-")
115 | funs.unshift("All Parameters")
116 | idx = TextMate::UI.menu(funs)
117 | TextMate.exit_discard if idx.nil?
118 | function = funs[idx]
119 | end
120 | TextMate.exit_discard if function.empty?
121 | curword = ENV['TM_CURRENT_WORD']
122 | comma=""
123 | line, col = ENV['TM_CURRENT_LINE'], ENV['TM_LINE_INDEX'].to_i
124 | left = line[0...col].to_s
125 | sp = left.match(/.$/).to_s
126 | left.gsub!(/ +$/,'')
127 | left = left.match(/.$/).to_s
128 | comma = "\${2:, }" if left != "(" && left != ","
129 | comma = " " + comma if sp == ","
130 | if function == "All Parameters"
131 | cnt=1
132 | com=""
133 | snip=""
134 | funs.slice!(0)
135 | funs.slice!(0)
136 | funs.each do |item|
137 | com = ", " if cnt > 1
138 | #if cnt%5 == 0
139 | # com = ",\n\t"
140 | #end
141 | if item.match("=")
142 | arr = item.gsub(/ = /, "=").match('([^=]+?)=(.*)')
143 | if arr[2].match('^\"')
144 | print "#{com}#{arr[1]} = \"\${"
145 | print cnt.to_s
146 | cnt+=1
147 | print ":#{arr[2].gsub(/^\"|\"$/, "").gsub(/=/, " = ")}}\""
148 | else
149 | if arr[2].match('^c\(')
150 | print "#{com}#{arr[1]} = c(\${"
151 | print cnt.to_s
152 | cnt+=1
153 | print ":#{arr[2].gsub(/^c\(/, "").gsub(/\)\Z/,"").gsub(/=/, " = ")}})"
154 | else
155 | print "#{com}#{arr[1]} = \${"
156 | print cnt.to_s
157 | cnt+=1
158 | print ":#{arr[2].gsub(/=/, " = ")}}"
159 | end
160 | end
161 | else
162 | print "#{com}#{item} = \${"
163 | print cnt.to_s
164 | cnt+=1
165 | print ":}"
166 | end
167 | end
168 | print "\${#{cnt}:}"
169 | else
170 | if function.match("=")
171 | arr = function.gsub(/ = /, "=").match('([^=]+?)=(.*)')
172 | if arr[2].match('^\"')
173 | print "#{comma}#{arr[1]} = \"\${1:#{arr[2].gsub(/^\"|\"$/, "")}}\"\${3:}"
174 | else
175 | if arr[2].match('^c\(')
176 | subarr = arr[2].gsub(/^c\(/, "").gsub(/\)$/,"").gsub(/ /,"").split(",")
177 | for i in (0..(subarr.size - 1))
178 | subarr[i] = "\${#{i+3}:#{subarr[i]}}"
179 | end
180 | print "#{comma}#{arr[1]} = \${1:c(#{subarr.join(", ")})}\${300:}"
181 | else
182 | print "#{comma}#{arr[1]} = \${1:#{arr[2].gsub(/=/, " = ")}}\${3:}"
183 | end
184 | end
185 | else
186 | print "#{comma}#{function} = \${1:}\${3:}"
187 | end
188 | end
189 | SCRIPT
190 |
--------------------------------------------------------------------------------
/Support/bin/insert_package_name.sh:
--------------------------------------------------------------------------------
1 |
2 | "$TM_BUNDLE_SUPPORT"/bin/askRhelperDaemon.sh "@getInstalledPackages()"
3 |
4 | cat "/tmp/textmate_Rhelper_out" | sort -f | ruby18 -e '
5 | isDIALOG2 = ! ENV["DIALOG"].match(/2$/).nil?
6 | require File.join(ENV["TM_SUPPORT_PATH"], "lib/ui.rb")
7 | require File.join(ENV["TM_SUPPORT_PATH"], "lib/exit_codes.rb")
8 | words = STDIN.read().split("\n")
9 | if isDIALOG2
10 | TextMate::UI.complete(words)
11 | else
12 | index=TextMate::UI.menu(words)
13 | end
14 | if index != nil
15 | print words[index]
16 | else
17 | TextMate.exit_discard()
18 | end
19 | exit 203
20 | '
--------------------------------------------------------------------------------
/Support/bin/parseDocForFunctions.sh:
--------------------------------------------------------------------------------
1 |
2 | USE=$(cat | egrep -A 10 "\b${1//./\\.}\b *<\-[ ]*\bfunction\b[ ]*\(" | perl -e '
3 | undef($/);
4 | $a=<>;
5 | $a=~s/.*?<\-\s*\bfunction\b\s*(\(.*?\))\s*[\t\n\{\w].*/$1/gms;
6 | $a=~s/"\n"/"\\n"/g;
7 | $a=~s/\x27\n\x27/\x27\\n\x27/g;
8 | $a=~s/[\n\t]/ /g;
9 | $a=~s/ {2,}/ /g;
10 | $a=~s/^\(\s*/(/g;
11 | $a=~s/\s*\)$/)/g;
12 | $a=~s/\s*=\s*/ = /g;
13 | $a=~s/\s*,\s*/, /g;
14 | print $a
15 | ')
16 |
17 | # If Rhelper doesn't work, use the following line only
18 | # echo $USE | fmt | perl -e 'undef($/);$a=<>;$a=~s/\n/\n\t/g;$a=~s/\n\t$//;print $a'
19 | if [ ! -z "$USE" ]; then
20 | "$TM_BUNDLE_SUPPORT"/bin/askRhelperDaemon.sh "TM_Rdaemona<-function $USE {};args(TM_Rdaemona)"
21 | # sleep 0.01
22 | OUT=$(cat /tmp/textmate_Rhelper_out | sed '$d' | perl -pe 's/^function //;s/"\n"/"\\n"/g;s/"\t"/"\\t"/g')
23 | if [ -z "$OUT" -a ! -z "$USE" ]; then
24 | echo " declaration possibly erroneous:
25 | $USE"
26 | else
27 | echo -n "$OUT"
28 | fi
29 | fi
--------------------------------------------------------------------------------
/Support/bin/parseHTMLForUsage.sh:
--------------------------------------------------------------------------------
1 |
2 | export WORD="$1"
3 | export FLAG="$2"
4 |
5 | # FLAG == 1 remove \n and function name for parameter parsing
6 | # FLAG == 0 show function usage
7 |
8 | cat | perl -e '
9 | undef($/);
10 | $w=$ENV{"WORD"};
11 | $f=$ENV{"FLAG"};
12 | $a=<>;
13 | $a=~s!.*?Usage\s*
[^>]*?($w\([^>]*?\)).*?\n.*?
.*!$1!ms;
14 | $a=~s/"\t"/"\\t"/sg;
15 | $a=~s/"\n"/"\\n"/sg;
16 | if($f) {
17 | $a=~s/\n//sg;
18 | $a=~s/^$w//ms;
19 | $a="" if($a!~m/^\(.*\)$/);
20 | }
21 | if($a!~m/^) {
22 | print $a;
23 | }
24 | '
25 |
--------------------------------------------------------------------------------
/Support/bin/prefix_package_name.sh:
--------------------------------------------------------------------------------
1 | [[ -n "$TM_SELECTED_TEXT" ]] && echo "Please unselect first." && exit 206
2 |
3 | LINE=$(cat | perl -e '
4 | $line=$ENV{"TM_CURRENT_LINE"};$col=$ENV{"TM_LINE_INDEX"};
5 | $lineL=substr($line,0,$col);
6 | $lineR=substr($line,$col);
7 | if($lineL=~m/([\w_\.]*)$/) {
8 | $lineL=~s/([\w_\.]*)$//;
9 | $lineR=$1.$lineR if(defined $1);
10 | }
11 | $lineL=~s/(?=[\$`\\])/\\/g;
12 | $lineR=~s/(?=[\$`\\])/\\/g;
13 | $lineR=~s/^([\w_\.]*)/$1\${0:}/;
14 | print "$lineL\n$lineR";
15 | ')
16 | WORD=$(ruby18 -- <<-SCR1
17 | require File.join(ENV["TM_SUPPORT_PATH"], "lib/current_word.rb")
18 | word = Word.current_word('\w._')
19 | print word
20 | SCR1
21 | )
22 |
23 | WORD=$(echo -en "$WORD" | perl -pe 's/\([^\(]*$//')
24 |
25 | [[ -z "$WORD" ]] && echo "No keyword found" && exit 206
26 |
27 | "$TM_BUNDLE_SUPPORT"/bin/askRhelperDaemon.sh "@getPackageFor('$WORD')"
28 | LIB=$(cat /tmp/textmate_Rhelper_out)
29 | if [ -z "$LIB" ]; then
30 | echo -en "No package found."
31 | exit 206
32 | fi
33 |
34 | if [ `echo "$LIB" | wc -l` -gt 1 ]; then
35 | LIB=$(echo "$LIB" | sort -f | ruby18 -e '
36 | require File.join(ENV["TM_SUPPORT_PATH"], "lib/ui.rb")
37 | require File.join(ENV["TM_SUPPORT_PATH"], "lib/exit_codes.rb")
38 | words = STDIN.read().split("\n")
39 | index=TextMate::UI.menu(words)
40 | if index != nil
41 | print words[index]
42 | end
43 | ')
44 | fi
45 | [[ -z $LIB ]] && exit 200
46 |
47 |
48 | OUT="${LINE/
49 | /$LIB::}"
50 | if [ `echo "$OUT" | grep -c "$LIB::"` -lt 1 ]; then
51 | echo "Please set the caret at the end of the function name and redo it."
52 | exit 206
53 | fi
54 | echo -n "$OUT"
55 |
--------------------------------------------------------------------------------
/Support/bin/startRhelperDaemon.sh:
--------------------------------------------------------------------------------
1 | RPID=$(ps aw | grep '[0-9] /.*TMRHelperDaemon' | awk '{print $1}' )
2 | #check whether Helper daemon runs if not start it
3 | if [ -z "$RPID" ]; then
4 | WDIR="$TM_BUNDLE_SUPPORT"/bin
5 | PIPE="/tmp/textmate_Rhelper_in"
6 | OUT="/tmp/textmate_Rhelper_console"
7 | cd "$WDIR"
8 | if [ ! -e "$PIPE" ]; then
9 | mkfifo "$PIPE"
10 | else
11 | if [ ! -p "$PIPE" ]; then
12 | rm "$PIPE"
13 | mkfifo "$PIPE"
14 | fi
15 | fi
16 | ruby18 RhelperDaemon.rb &> /dev/null &
17 | SAFECNT=0
18 | while [ 1 ]
19 | do
20 | SAFECNT=$(($SAFECNT+1))
21 | if [ $SAFECNT -gt 5000 ]; then
22 | echo -en "Start failed! No response from R Helper server!"
23 | exit 206
24 | fi
25 | RES=$(tail -c 2 "$OUT")
26 | [[ "$RES" == "> " ]] && break
27 | sleep 0.03
28 | done
29 | sleep 0.3
30 | cat "" > /tmp/textmate_Rhelper_data.html
31 | fi
32 |
--------------------------------------------------------------------------------
/Support/bin/startRhelperbuilder.sh:
--------------------------------------------------------------------------------
1 |
2 |
3 | ################################
4 | ## NOT YET USED !!!!!
5 | ################################
6 |
7 |
8 | WDIR="$TM_BUNDLE_SUPPORT"/bin
9 | HTMLROOTPATH="$HOME/Library/Application Support/TextMate/R/help/HTML"
10 |
11 | [[ ! -e "$HTMLROOTPATH" ]] && mkdir -p "$HTMLROOTPATH"
12 |
13 | cd "$WDIR"
14 |
15 | if [ ! -e /tmp/r_helper_dummy ]; then
16 | mkfifo /tmp/r_helper_dummy
17 | else
18 | if [ ! -p /tmp/r_helper_dummy ]; then
19 | rm /tmp/r_helper_dummy
20 | mkfifo /tmp/r_helper_dummy
21 | fi
22 | fi
23 |
24 | ruby18 Rhelperbuilder.rb &> /dev/null &
25 |
26 | ### wait for Rhelper
27 | #safety counter
28 | SAFECNT=0
29 | while [ ! -f /tmp/r_helper_dummy_out ]
30 | do
31 | SAFECNT=$(($SAFECNT+1))
32 | if [ $SAFECNT -gt 50000 ]; then
33 | echo -en "Start failed! No response from Rhelper!"
34 | exit 206
35 | fi
36 | sleep 0.01
37 | done
38 |
39 | #wait for Rdaemon's output is ready
40 | SAFECNT=0
41 | while [ 1 ]
42 | do
43 | ST=$(tail -n 1 /tmp/r_helper_dummy_out )
44 | [[ "$ST" == "> " ]] && break
45 | SAFECNT=$(($SAFECNT+1))
46 | if [ $SAFECNT -gt 50000 ]; then
47 | echo -en "Start failed! No response from Rhelper!"
48 | exit 206
49 | fi
50 | sleep 0.05
51 | done
52 |
53 | exec<"$TM_BUNDLE_SUPPORT/helpshort.index"
54 | # SAFECNT=0
55 | export token=$("$DIALOG" -a ProgressDialog -p "{title=Rdaemon;isIndeterminate=1;summary='R Documentation';details='Create HTML help pages…';}")
56 | while read line
57 | do
58 | OLDIFS="$IFS"
59 | IFS="/"
60 | data=( $line )
61 | # fun=$(echo -n $line | cut -d '/' -f2)
62 | # lib=$(echo -n $line | cut -d '/' -f1)
63 | [[ ! -e "$HTMLROOTPATH/${data[0]}" ]] && mkdir -p "$HTMLROOTPATH/${data[0]}"
64 | file="$HTMLROOTPATH/${data[0]}/${data[1]}.html"
65 | if [ ! -e "$file" ]; then
66 | curl -sS "http://127.0.0.1:30815/library/${data[0]}/html/${data[1]}.html" > "$file"
67 | fi
68 | # SAFECNT=$(($SAFECNT+1))
69 | # [[ $SAFECNT -gt 50 ]] && break
70 | done
71 | "$DIALOG" -x $token 2&>/dev/null
72 |
73 |
74 | sleep .1
75 | echo "q('no')" > /tmp/r_helper_dummy
76 | rm /tmp/r_helper_dummy
77 | rm /tmp/r_helper_dummy_out
78 |
--------------------------------------------------------------------------------
/Support/getSig.R:
--------------------------------------------------------------------------------
1 | getSig <- function (..., snippet=T)
2 | sapply(unlist(list(...)), function(name, snipIdx=0, argIdx=0)
3 | paste(c(name, "(",
4 | if (snippet && is.null(formals(name)))
5 | "$1"
6 | else
7 | lapply(
8 | lapply(names(f <- formals(name)),
9 | function (arg)
10 | if (is.symbol(f[[arg]]) && f[[arg]] == "") arg else list(arg, f[[arg]])
11 | ),
12 | function (arg, escape=function(x) ifelse(snippet, gsub(" *\n +", " ", gsub("([\\$`}])", "\\\\\\1", x)), x))
13 | if (is.list(arg))
14 | paste(if (snippet) paste("${", snipIdx <<- snipIdx + 1, ":", sep=""),
15 | ifelse((argIdx <<- argIdx + 1) > 1, ", ", ""),
16 | escape(deparse(as.name(arg[[1]]), backtick=T)),
17 | "=",
18 | if (snippet) paste("${", snipIdx <<- snipIdx + 1, ":", sep=""),
19 | if (is.character(arg[[2]]))
20 | paste('"',
21 | if (snippet) paste('${', snipIdx <<- snipIdx + 1, ":", sep=""),
22 | escape(substr(deparse(arg[[2]]), 2, nchar(deparse(arg[[2]]),type="c")-1)),
23 | ifelse(snippet, '}', ""),
24 | '"',
25 | sep=""
26 | )
27 | else
28 | escape(paste(deparse(arg[[2]], backtick=T, control="useSource"), collapse="\n"))
29 | ,
30 | ifelse(snippet, "}}", ""),
31 | sep="")
32 | else
33 | paste(ifelse((argIdx <<- argIdx + 1) > 1,
34 | ifelse(snippet, paste("${", snipIdx <<- snipIdx + 1, ":, ", sep=""), ", "),
35 | ""),
36 | if (snippet) paste("${", snipIdx <<- snipIdx + 1, ":", sep=""),
37 | escape(arg),
38 | ifelse(snippet, ifelse(argIdx > 1, "}}", "}"), ""),
39 | sep="")
40 | )
41 | ,
42 | ")")
43 | , collapse=""
44 | )
45 | )
46 |
--------------------------------------------------------------------------------
/Support/getSigTest.R:
--------------------------------------------------------------------------------
1 | # This file is just used for testing getSig.R
2 | # I committed it to the repo so it can be used for further maintenance of getSig.R
3 | #
4 | # Kevin Ballard
5 |
6 | source("./getSig.R")
7 |
8 | # function to use in testing symbols
9 | fubar <- function (x, y=`+`, z=if (T) "foo" else "bar", q="haha", `a a`=c("heavy", "medium", "light"), meth=mean) {
10 | do.call(y, as.list(x))
11 | }
12 |
13 | # cat(paste(getSig(if ('p' %in% (ary <- sort(apropos('^p', mode='function')))) 'p' else ary), collapse='\n'))
14 | cat(paste(getSig("fubar"), collapse="\n"))
15 |
--------------------------------------------------------------------------------
/Support/lib/command_args/dist:
--------------------------------------------------------------------------------
1 | x
2 | method="euclidean|maximum|manhattan|canberra|binary|minkowski"
3 | diag=FALSE
4 | upper=FALSE
5 | p = 2
--------------------------------------------------------------------------------
/Support/lib/command_args/getOption:
--------------------------------------------------------------------------------
1 | "add.smooth"
2 | "check.bounds"
3 | "continue"
4 | "defaultPackages"
5 | "deparse.max.lines"
6 | "digits"
7 | "digits.secs"
8 | "download.file.method"
9 | "echo"
10 | "encoding"
11 | "error"
12 | "expressions25...500000"
13 | "keep.source"
14 | "keep.source.pkgs"
15 | "mailer"
16 | "max.contour.segments"
17 | "max.print"
18 | "OutDec"
19 | "pager"
20 | "papersize"
21 | "printcmd"
22 | "prompt"
23 | "rl_word_breaks"
24 | "save.defaults"
25 | "save.image.defaults"
26 | "scipen"
27 | "showErrorCalls"
28 | "showWarnCalls"
29 | "showNCalls"
30 | "show.error.messages"
31 | "stringsAsFactors"
32 | "texi2dvi"
33 | "timeout"
34 | "topLevelEnvironment"
35 | "useFancyQuotes"
36 | "verbose"
37 | "warn"
38 | "warnPartialMatchArgs"
39 | "warnPartialMatchAttr"
40 | "warnPartialMatchDollar"
41 | "warning.expression"
42 | "warnings.length"
43 | "width"
44 | -
45 | "device"
46 | "locatorBell"
47 | "par.ask.default"
48 | "X11colortype"
49 | "X11fonts"
50 | "gamma"
51 | -
52 | "contrasts"
53 | "na.action"
54 | "show.coef.Pvalues"
55 | "show.signif.stars"
56 | "ts.eps"
57 | "ts.S.compat"
58 | -
59 | "browser"
60 | "de.cellwidth"
61 | "editor"
62 | "example.ask"
63 | "help.try.all.packages"
64 | "HTTPUserAgent"
65 | "internet.info"
66 | "menu.graphics"
67 | "pkgType"
68 | "repos"
69 | "SweaveHooks"
70 | "SweaveSyntax"
71 | "unzip"
72 | "-
73 | "dvipscmd"
74 | "latexcmd"
75 | "pdfviewer"
--------------------------------------------------------------------------------
/Support/lib/command_args/lines:
--------------------------------------------------------------------------------
1 | type="p|l|b|c|o|h|s|S|n"
--------------------------------------------------------------------------------
/Support/lib/command_args/mean:
--------------------------------------------------------------------------------
1 | trim=0
2 | na.rm=TRUE
--------------------------------------------------------------------------------
/Support/lib/command_args/options:
--------------------------------------------------------------------------------
1 | add.smooth=TRUE
2 | check.bounds=FALSE
3 | continue="+ "
4 | defaultPackages=c("datasets", "utils", "grDevices", "graphics", "stats", "methods")
5 | deparse.max.lines=10
6 | digits=7
7 | digits.secs=0...6
8 | download.file.method="internal|wget|lynx|auto"
9 | echo=TRUE
10 | encoding="native.enc"
11 | error=NULL|fun
12 | expressions25...500000
13 | keep.source=TRUE
14 | keep.source.pkgs=FALSE
15 | mailer="none"
16 | max.contour.segments=250000
17 | max.print=99999
18 | OutDec="."
19 | pager="$R_HOME/bin/pager"
20 | papersize=""
21 | printcmd=""
22 | prompt="> "
23 | rl_word_breaks=" \t\n\"\\`><=%;,|&{()}"
24 | save.defaults=list(ascii=TRUE, safe=FALSE)
25 | save.image.defaults=list(ascii=TRUE, safe=FALSE)
26 | scipen=integer_positiveFixed|negativeScientific
27 | showErrorCalls=TRUE
28 | showWarnCalls=TRUE
29 | showNCalls=30...500
30 | show.error.messages=TRUE
31 | stringsAsFactors=TRUE
32 | texi2dvi="NULL|script"
33 | timeout=60
34 | topLevelEnvironment=""
35 | useFancyQuotes=TRUE
36 | verbose=TRUE
37 | warn=-1-ignore|0-default|1-as_occur|2-as_error
38 | warnPartialMatchArgs=TRUE
39 | warnPartialMatchAttr=TRUE
40 | warnPartialMatchDollar=TRUE
41 | warning.expression="func"
42 | warnings.length=100...8170
43 | width=10...10000
44 | -
45 | device="x11|quartz|postscript|pdf"
46 | locatorBell=TRUE
47 | par.ask.default=TRUE
48 | X11colortype="true"
49 | X11fonts=c("", "")
50 | gamma=1
51 | -
52 | contrasts=c("unordered", "ordered")
53 | na.action="func"
54 | show.coef.Pvalues=TRUE.
55 | show.signif.stars=TRUE
56 | ts.eps=1e-05
57 | ts.S.compat=TRUE
58 | -
59 | browser="Safari"
60 | de.cellwidth=|0|negative|NA
61 | editor="mate -w"
62 | example.ask=TRUE
63 | help.try.all.packages=TRUE
64 | HTTPUserAgent="NULL"
65 | internet.info=2|1|0
66 | menu.graphics=FALSE
67 | pkgType="source|mac.binary"
68 | repos=c(CRAN="@CRAN@")
69 | SweaveHooks=""
70 | SweaveSyntax=""
71 | unzip="internal|PATH"
72 | -
73 | dvipscmd="command"
74 | latexcmd="command"
75 | pdfviewer=""
--------------------------------------------------------------------------------
/Support/lib/command_args/par:
--------------------------------------------------------------------------------
1 | adj=0-left|0.5-center|1-right
2 | ann=FALSE
3 | ask=TRUE
4 | bg=""
5 | bty="o|l|7|c|u|n|]"
6 | cex=1
7 | cex.axis=1
8 | cex.lab=1
9 | cex.main=1
10 | cex.sub=1
11 | col="red"
12 | col.axis="red"
13 | col.lab="red"
14 | col.main="red"
15 | col.sub="red"
16 | crt=0
17 | family=""
18 | fg="red"
19 | fig=c(1, 1, 1, 1)
20 | fin=c(width, height)
21 | font=1-plain|2-bold|3-italics|4-bolditalics
22 | font.axis=1-plain|2-bold|3-italics|4-bolditalics
23 | font.lab=1-plain|2-bold|3-italics|4-bolditalics
24 | font.main=1-plain|2-bold|3-italics|4-bolditalics
25 | font.sub=1-plain|2-bold|3-italics|4-bolditalics
26 | gamma=1
27 | lab=c(x, y, len)
28 | las=0-parallel|1-horizontal|2-perpendicular|3-vertical
29 | lend=0-round|1-butt|2-square
30 | lheight=1
31 | ljoin=0-round|1-mitre|2-bevel
32 | lmitre=10
33 | lty=0-blank|1-solid|2-dashed|3-dotted|4-dotdash|5-longdash|6-twodash
34 | lwd=1
35 | mai=c(bottom, left, top, right)
36 | mar=c(bottom, left, top, right)
37 | mex=1
38 | mfcol=c(nr, nc)
39 | mfg=c(i, j)
40 | mfrow=c(nr, nc)
41 | mgp=c(3, 1, 0)
42 | new=TRUE
43 | oma=c(bottom, left, top, right)
44 | omd=c(x1, x2, y1, y2)
45 | omi=c(bottom, left, top, right)
46 | pch="19-solidCircle|20-bullet|21-circle|22-square|23-diamond|24-triangleUp|25-triangleDown"
47 | pin=c(width, height)
48 | plt=c(x1, x2, y1, y2)
49 | ps=10
50 | pty="s|m"
51 | srt=0
52 | tck=1
53 | tcl=-0.5
54 | usr=c(x1, x2, y1, y2)
55 | xaxp=c(x1, x2, 1|2|3)
56 | xaxs="r|i|e|s|d"
57 | xaxt="n|s|l|t"
58 | xlog=TRUE
59 | xpd=TRUE|FALSE|NA
60 | yaxp=c(x1, x2, 1|2|3)
61 | yaxs="r|i|e|s|d"
62 | yaxt="n|s|l|t"
63 | ylog=TRUE
--------------------------------------------------------------------------------
/Support/lib/command_args/plot:
--------------------------------------------------------------------------------
1 | asp="y/x aspect ratio"
2 | log="x|y|xy|yx"
3 | main="title"
4 | sub="subtitle"
5 | type="p|l|b|c|o|h|s|S|n"
6 | xlab="x-title"
7 | xlog=TRUE
8 | ylab="y-title"
9 | ylog=TRUE
10 |
--------------------------------------------------------------------------------
/Support/lib/command_args/points:
--------------------------------------------------------------------------------
1 | type="p|l|b|c|o|h|s|S|n"
--------------------------------------------------------------------------------
/Support/lib/help.markdown:
--------------------------------------------------------------------------------
1 | # Introduction
2 |
3 | R is a language and environment for statistical computing and graphics. It is a [GNU project](http://www.gnu.org/) which is similar to the S language and environment which was developed at Bell Laboratories (formerly AT&T, now Lucent Technologies) by John Chambers and colleagues. R can be considered as a different implementation of S. There are some important differences, but much code written for S runs unaltered under R.
4 |
5 | R provides a wide variety of statistical (linear and non-linear modeling, classical statistical tests, time-series analysis, classification, clustering, ...) and graphical techniques, and is highly extensible. The S language is often the vehicle of choice for research in statistical methodology, and R provides an Open Source route to participation in that activity.
6 |
7 | (Text taken from [What is R?](http://www.r-project.org/about.html))
8 |
9 | More information about R can be found at [r-project.org](http://www.r-project.org/).
10 |
11 | ⇢ This bundle requires a R version >= R 3.2
12 |
13 | # Commands
14 |
15 | ## Run Selection/Document In R
16 |
17 | It executes the current document or selection (if the selection only contains out-commented R code the current document) in a self-sufficient environment of the command-line version of R and it displays the output in an HTML window. By default new plots use the "pdf" device and are placed in a temporary folder and displayed at the end of the HTML window.
18 |
19 | ## Execute Selection/Document In R (Insert/Pasteboard/Tooltip)
20 |
21 | It executes the current document or selection in a self-sufficient environment of the command-line version of R. The output will be inserted, or will be copied into the pasteboard, or will be shown as Tooltip or.
22 |
23 | ## Send Selection/Document to Rdaemon
24 |
25 | It sends the current document or selection line by line to the Rdaemon. If Rdaemon is installed and it is not yet running it will start it, it opens the Rsession project, and the file `~/Library/Application Support/Rdaemon/console.Rcon` will contain the output.
26 |
27 | ***Hint*** To use that command you have to install the Rdaemon Bundle in beforehand.
28 |
29 | ## Send Selection/Document to R.app
30 |
31 | It executes the current document or selection in R.app and switches to R.app's Console.
32 |
33 | ***Hint*** To use that command you have to install R.app in beforehand.
34 |
35 | ## Send Selection/Document to R.app & Step
36 |
37 | It executes the current line or selection in R.app and goes to the end of the next line. TextMate keeps its focus.
38 |
39 | ***Hint*** To use that command you have to install R.app in beforehand.
40 |
41 | ## Completion…
42 |
43 | Based on all installed packages and local function declarations within the current R script it shows an inline menu with completion suggestions for the current word or selection as function [library] or as command …local… indicating that `function` is defined within the current R script.
44 |
45 | If the “Completion…” command is invoked from a running Rdaemon document the notation function {library} indicates that the `library` is not loaded (or `function` is not found as valid function name in a loaded library) whereby the notation function …library… indicates that `library` is loaded.
46 |
47 | As default it also displays an inline menu if there is only one suggestion found in order to give you an hint about the required library. You can force TextMate to complete it without displaying that menu by setting the TextMate shell variable `TM_R_AUTOCOMPLETE` to `1`.
48 |
49 | ***Hint*** This command works case-sensitively. E.g. if you type `math` (without selection and there is no command beginning with `math`) and invoke this command it lists all case-insensitive matched commands like `Math.fraction`, etc. as a tooltip caused by the chosen "Insert as Snippet" mechanism.
50 |
51 | ## Show R Help for actual Word/Selection
52 |
53 | It shows an HTML document with the found R help for the current word or of that command in which the caret is located. If no help file is found it opens an HTML window with all found keywords beginning with the current word. Furthermore this help window offers a `Search for` field to enter a new search term (a regular expression). The check box `Begins with` adds a `^` at the beginning of the search term. The search makes usage of the R command `help.search(TERM)`.
54 |
55 | ***Hint*** The search function `help.search` allows to look for the entered term case-sensitively by using the regular expression flag `(?-i)` e.g. to look exactly for `T` type `“(?-i)^T$”` whereby ^ means look only from the beginning of an help entry and $ means to look until the end of an help entry.
56 |
57 | ## Show Function Usage
58 |
59 | Based on all installed packages and local function declarations it shows a tooltip with the function signature for the current word — or that command in which the caret is located in respect of nested parentheses — or of the selection.
60 |
61 | ## Show Function Usage + Insert “(”
62 |
63 | Based on all installed packages and local function declarations it shows a tooltip with the function signature for the current word and it inserts “()” or “(”.
64 |
65 | ***Hint*** This command will run in a background task to avoid waiting for unknown commands or if lots of packages are installed. This functionality can be switched off by deactivating the bound key equivalent within in the Bundle Editor.
66 |
67 | ## Function Parameter…
68 |
69 | It shows an inline menu with all available parameters and inserts a snippet with the chosen one(s). This command also tries to figure out whether it is necessary to insert a comma “, ”. If the inserted comma “, ” is set falsely one can press twice to highlight it.
70 |
71 | ***Hint*** It is possible to write its own parameter list for given functions. These lists have to be saved in `~/Library/Application Support/TextMate/R/lib/command_args` and the file name represents exactly the function name. Invoke simply the command `“R” → “Documentation” → “Edit user-defined Function Parameter”` to edit those parameter lists.
72 |
73 | See here an example for `$TM_BUNDLE_SUPPORT/lib/command_args/plot`:
74 |
75 |
86 |
87 | ## “par()” Parameters…
88 |
89 | It shows an inline menu with all parameters defined in `$TM_BUNDLE_SUPPORT/lib/command_args/par` and inserts a snippet with the chosen one(s). This command also tries to figure out whether it is necessary to insert a comma “, ”. If the inserted comma “, ” is set falsely one can press twice to highlight it.
90 |
91 | ## “require(xxx)” for current Function
92 |
93 | It looks for that package in which the current keyword — "()" will be recognized — is defined, and it inserts the R code to load that package `require(PACKAGE)` above the current line.
94 |
95 | ## Prefix Package Name to current Function
96 |
97 | It prefixes the current function with the found package name. Useful e.g. if a function occurs in more than one loaded package.
98 |
99 | ## Package Name…
100 |
101 | It shows all installed packages as an inline menu.
102 |
103 | ## Option List as Pull Down… / BoolToggler
104 |
105 | This is an auxiliary tool command with these two different tasks based on a selection:
106 |
107 | * It negates the logical value if the selection is "FALSE" or "TRUE" and "F" or "T" resp.
108 | * It shows an inline menu of all values which are selected and delimited by "|" and replaces the selection by the chosen one.
109 |
110 | For instance this is useful after inserting the parameter `method` of the R function `dist`. The selected value is:
111 | `euclidean|maximum|manhattan|canberra|binary|minkowski`
112 |
113 | or if the selected value (like for `par`, parameter `font.lab`) is:
114 | `1-plain|2-bold|3-italics|4-bolditalics`
115 |
116 | it only inserts the according digits.
117 |
118 | ## Create Vector/Matrix from Selection
119 |
120 | It inserts a vector in the form of `x <- c(x1, x2, ...)` resp. `x <- matrix(c(x1, x2, ...))` as snippet taken from a selected string or the current content of the clipboard. Delimiters are " ", "↩", or "⇥". If an element doesn't consist of digits the element will be enclosed by double-quotes. It won't be checked for creating a matrix whether the length of the vector is a sub-multiple of the numbers of rows.
121 |
122 | ## Show File Header
123 | If one only selects a file path this command shows you the first three lines of that file as tooltip. Useful for the import of data files to determine the its structure or whether the data file has an header or not etc.
124 |
125 | ## Next/Previous List Element/Parameter Value
126 |
127 | It tries to highlight the next/previous element (if quoted only the content) of a list/vector or the value of function parameters.
128 |
129 | ## Tidy (removes all comments!)
130 |
131 | It tidies the selection or the entire document by deparsing them on-the-fly using the command-line version of R. General syntax errors will be displayed as tooltip and the caret will be moved to the first error.
132 |
133 | Attention: All comments will be deleted!
134 |
135 | ***Hint*** This command can also be used as a kind of `Syntax Checker`. It only checks the R code for general syntax error like missing brackets, or commas, etc. It does **not** check for semantic errors like if a variable was assigned correctly or not.
136 |
137 | ## Function Call
138 |
139 | It inserts: sum(SELECTION/WORD) as snippet. The default function can be set via the shell variable `TM_R_WRAP_DEFAULT_FUNCTION`.
140 |
141 | ## Function Definition
142 |
143 | It inserts:
as snippet.
147 |
148 | ## Drag&Drop Facilities
149 | - __load (*.Rdata)__
150 |
151 | If a `*.Rdata` or `*.Rda` file is drag&dropped to a R/R console document it inserts:
152 |
153 | `load(FILE)`.
154 |
155 | By pressing SHIFT while dragging it inserts the absolute file path.
156 |
157 | - __source (*.R)__
158 |
159 | If a `*.R` file is drag&dropped to a R/R console document it inserts:
160 |
161 | source(FILE, chdir = TRUE).
162 |
163 | By pressing SHIFT while dragging it inserts the absolute file path.
164 |
165 | - __read.csv (*.csv)__
166 |
167 | If a `*.csv` file is drag&dropped to a R/R console document it inserts:
168 |
169 | read.csv(file = FILE, header = TRUE, stringsAsFactors = FALSE).
170 |
171 | By pressing SHIFT while dragging it inserts the absolute file path.
172 |
173 | - __read.table (*.tab)__
174 |
175 | If a `*.tab` file is drag&dropped to a R/R console document it inserts:
176 |
177 | read.table(file = FILE, sep = \t, header = TRUE, stringsAsFactors = FALSE).
178 |
179 | By pressing SHIFT while dragging it inserts the absolute file path.
180 |
181 | # TextMate Shell Variables
182 |
183 | ## TM_R_AUTOCOMPLETE
184 |
185 | As default TextMate displays an inline menu if there is only one suggestion found in order to give you an hint for the required library. You can force TextMate to complete it without displaying that menu by setting the shell variable `TM_R_AUTOCOMPLETE` to `1`. See also [Completion…](#sect_2.5).
186 |
187 | ## TM_R_WRAP_DEFAULT_FUNCTION
188 |
189 | Set the default function for “Wrap Selection → Function Call” ^⇧W. If unset `sum` will be taken.
190 |
191 | ## TM_R_SHOW_ALWAYS_HELPSEARCH
192 |
193 | As default `Show R Help for actual Word` opens a single window without a search field if the actual word matches one keyword. To avoid this set that shell variable to “1”.
194 |
195 | ## TM_REXEC
196 |
197 | If not set a R session will be invoked by R --vanilla --slave --encoding=UTF-8 otherwise, if set e.g. to "R32", a R session will be invoked by R32 --vanilla --slave --encoding=UTF-8 in order to be able to start R explicitly in 64 ("R64") or 32 ("R32") bit mode. In addition it also allows to add more command line arguments like "R32 --verbose" will execute R32 --verbose --vanilla --slave --encoding=UTF-8.
198 |
199 | ## TM_RMATE_OUTPUT_FONT
200 |
201 | Set the font of Rmate's output window. Default is set to “Monaco”.
202 |
203 | ## TM_RMATE_OUTPUT_FONTSIZE
204 |
205 | Set the font size of Rmate's output window. Default is set to “10”.
206 |
207 | ## TM_RMATE_ENABLE_LINECOUNTER
208 |
209 | For debugging large R scripts it could be useful to have the chance to use the outputted leading prompt > as hyperlink to jump into the corresponding line of the R script. For that purpose you can set this shell variable to “1”. Please note that by enabling it the script **may not** contain multi-line string declarations, otherwise the string variables will be erroneous (these strings contain the internal string marker #§*).
210 |
211 | # Troubleshooting & FAQ
212 |
213 | - __`'re-encoding is not available on this system'` or `'object ".PSenv" not found'`__
214 |
215 | If you see one of these messages then you are most likely using an older version of R. In this case you should upgrade to the latest (currently, version 2.6.1) by downloading the pre-built universal R.app installer from r-project.org.
216 |
217 | - __`115:116: syntax error: Expected end of line, etc. but found “. (-2741)`__
218 |
219 | If you see such an error (or similar) while sending something to "R.app" it is very likely that you are also running the "Rdaemon" with loaded "CarbonEL". Unfortunately "CarbonEL" uses the same application name "R", thus the AppleScript will send the R code to it, not to "R.app". In such a case you have to quit the Rdaemon.
220 |
221 | - __.../R.tmbundle/Support/lib/popen3.rb:18: warning: Insecure world writable dir "DIR" in PATH, mode 040777__
222 |
223 | If Rmate is outputting this warning message it is very likely that "DIR" has write permissions set to **group** and **others**. To change the permission for that "DIR" run this command from a Terminal window:
224 |
225 | `chmod og-w 'DIR'`
226 |
227 | - __`Text strings defined as multi-line declarations inside a R script contain " #§*"`__
228 |
229 | Please disable TextMate's shell variable TM_RMATE_ENABLE_LINECOUNTER.
230 |
231 | # The bundle "R Console (Rdaemon)"
232 |
233 | In addition there is the bundle "R Console (Rdaemon)" available. This bundle allows to run the command-line version of R ***inside*** TextMate. A normal document window, which is set to the language "R Console (Rdaemon)", serves as R console. More details within this bundle.
234 |
235 | # The bundle "R Console (R.app)"
236 |
237 | In addition there is the bundle "R Console (R.app)" available. This bundle allows to remote the Mac OSX GUI "R.app". More details within this bundle.
238 |
239 | # Main Bundle Maintainer
240 |
241 | ***Date: May 14 2015***
242 |
243 |