大智慧龙软DTSR语言量化投资云培训RStudio学习手册中文翻译模板.docx

上传人:满*** 文档编号:97992108 上传时间:2024-07-08 格式:DOCX 页数:54 大小:1.56MB
返回 下载 相关 举报
大智慧龙软DTSR语言量化投资云培训RStudio学习手册中文翻译模板.docx_第1页
第1页 / 共54页
大智慧龙软DTSR语言量化投资云培训RStudio学习手册中文翻译模板.docx_第2页
第2页 / 共54页
点击查看更多>>
资源描述

《大智慧龙软DTSR语言量化投资云培训RStudio学习手册中文翻译模板.docx》由会员分享,可在线阅读,更多相关《大智慧龙软DTSR语言量化投资云培训RStudio学习手册中文翻译模板.docx(54页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、Working in the Console 控制台中工作Overview 概述The RStudio console includes a variety of features intended to make working with R more productive and straightforward. This article reviews these features. Learning to use these features along with the related features available in the Source and History pane

2、s can have a substantial payoff in your overall productivity with R. RStudio控制台包含很多使R工作更为有效和直观特征。本文综述这些特征。学习使用这些特征和Source和History窗口中可用相关特征能够对你使用R效率有实际性帮助。Code Completion 代码补全RStudio supports the automatic completion of code using the Tab key. For example, if you have an object named pollResults in y

3、our workspace you can type poll and then Tab and RStudio will automatically complete the full name of the object.RStudio支持使用Tab键来自动补全代码。比如,假如你在工作空间中有名为pollResults对象,你可输入poll然后按Tab键,RStudio将自动完成该对象全名。The code completion feature also provides inline help for functions whenever possible. For example, i

4、f you typed sub then pressed Tab you would see:代码补全特征一样提供了尽可能嵌入式帮助。比如,假如你可输入sub然后按Tab键,你将看到:Code completion also works for function arguments, so if you typed subset( and then pressed Tab youd see the following:代码补全还能够对参数功效进行工作,假如你可输入subset(然后按Tab键,你将看到:Retrieving Previous Commands 检索以前命令As you work

5、 with R youll often want to re-execute a command which you previously entered. As with the standard R console, the RStudio console supports the ability to recall previous commands using the arrow keys:当你使用R进行工作,你将常常可输入重新实施你之前输入命令。和标准R控制台一样,RStudio控制台支持使用以下方向键回想之前命令功效: Up Recall previous command(s) D

6、own Reverse of Up Up 回想前一条命令; Down 回Up相反;If you wish to review a list of your recent commands and then select a command from this list you can use Ctrl+Up to review the list (note that on the Mac you can also use Command-Up): 假如你期望回顾你目前命令列表并从中选择一条命令,则可使用Ctrl+Up往返顾命令列表(注意:在Mac你还可使用Command-Up)You can

7、also use this same keyboard shortcut to quickly search for commands that match a given prefix. For example, to search for previous instances of the plot function simply type plot and then Ctrl+Up:你还能够使用一样快捷键来快速查找匹配给定前缀命令。比如,查找前面出现过plot函数,先输入plot然后Ctrl+UpConsole Title Bar 控制台标题栏This screenshot illust

8、rates a few additional capabilities provided by the Console title bar:这个截屏说明了控制台标题栏部分额外功效。 Display of the current working directory. The ability to interrupt R during a long computation. Minimizing and maximizing the Console in relation to the Source pane (using the buttons at the top-right or by do

9、uble-clicking the title bar). 显示目前工作目录; 能够在一个长久计算里中止R; 最小化和最大化Console和Source窗口(使用右上按钮或双击标题栏)Keyboard Shortcuts 快捷键Beyond the history and code-completion oriented keyboard shortcuts described above, there are a wide variety of other shortcuts available. Some of the more useful shortcuts include: 除了上述

10、历史和代码补全快捷键外,还有很多其它快捷键可用,其中最为有用快捷键包含 Ctrl+1 Move focus to the Source Editor Ctrl+2 Move focus to the Console Ctrl+L Clear the Console Esc Interrupt R Ctrl+1 移动焦点到Source编辑器。 Ctrl+2 移动焦点到Console。 Ctrl+L 清理控制台; Esc 中止RYou can find a list of all shortcuts in the Keyboard Shortcuts article. 你可从Keyboard Sh

11、ortcuts文中找到全部快捷键列表。Related Topics 相关专题 Editing and Executing Code 编辑和实施代码 Using Command History 使用命令历史Editing and Executing Code 编辑实施代码Overview 概述RStudios source editor includes a variety of productivity enhancing features including syntax highlighting, code completion, multiple-file editing, and fi

12、nd/replace.RStudiosouce编辑器包含多种提升效率特征,包含语法高亮显示,代码自动补全,多文件编辑和查找和替换。RStudio also enables you to flexibly execute R code directly from the source editor. For many R developers this represents their preferred way of working with R. By executing commands from within the source editor rather than the conso

13、le it is much easier to reproduce sequences of commands as well as package them for re-use as a function. These features are described in the Executing Code section below.RStudio还能够使你直接经过source编辑器灵活地实施R代码。对于很多R开发者来说,这是她们使用R首选方法。经过source编辑器实施命令相对于控制台来说更便于复制命令序列和将其做为再次使用函数进行打包;这些特征将在后面实施代码部分讲解。Managin

14、g Files 文件管理RStudio supports syntax highlighting and other specialized code-editing features for the following types of files:Rstudio支持语法高亮显示和其它专业化代码编辑功效,针对以下类型文件。 R scripts R脚本文件 Sweave documents Sweave文件 TeX documents Tex文件To create a new file you use the File - New menu: 你可经过File - New菜单创建新文件。(你也

15、可使用Ctrl+Shift+N快捷键)。To open an existing file you use either the File - Open menu or the Open Recent menu to select from recently opened files. 你可经过File - Open菜单或Open Recent菜单选择来打开已经有文件。(你也可使用Ctrl+O快捷键)。If you open several files within RStudio they are all available as tabs to facilitate quick switch

16、ing between open documents. If you have a large number of open documents you can also navigate between them using the icon on the tab bar or the View - Switch to Tab) menu item:假如你经过RStudio打开很多文件,那么她们全部能够经过标签进行快速切换。假如你有大量打开文件,你也可在它们间经过标签栏中图标来进行导航,或View - Switch to Tab菜单项(你也可使用Ctrl+O快捷键)。Code Complet

17、ion 代码补全RStudio supports the automatic completion of code using the Tab key. For example, if you have an object named pollResults in your workspace you can type poll and then Tab and RStudio will automatically complete the full name of the object.RStudio能够使用Tab键来支持代码自动补全,比如,假如你在工作空间中有名为pollResults对象

18、,你可输入poll然后按Tab键,RStudio将自动完成该对象全名。Code completion also works in the console, and more details on using it can be found the console Code Completion documentation. 代码补全一样在控制台中工作,具体使用方法可间控制台代码自动完成Code Completion文档。Find and Replace 查找和替换RStudio supports finding and replacing text within source document

19、s: Rstudio支持在source文件中查找和替换。Find and replace can be opened using the Ctrl+F shortcut key, or from the Edit - Find and Replace menu item.可使用Ctrl+F快捷键来打开查找和替换栏,或使用Edit - Find and Replace菜单项。Extract Function 提取函数RStudio can analyze a selection of code from within the source editor and automatically con

20、vert it into a re-usable function. Any free variables within the selection (objects that are referenced but not created within the selection) are converted into function arguments:RStudio能够在source编辑器中分析一组选择代码,并自动将其转化成再次使用函数。任何选择中free变量(选择引用对象但不创建)将转化为函数参数。(你也可使用Ctrl+Shift+U快捷键)。Comment/Uncomment 注释/

21、取消注释You can comment and uncomment entire selections of code using the Edit - Comment/Uncomment Lines menu item (you can also do this using the Ctrl+/ keyboard shortcut):你可使用使用Edit - Comment/Uncomment Lines菜单项来对所选整个代码进行注释或取消注释(你也可使用Ctrl+Shift+C快捷键)。Indentation 首行缩进As you write R code in RStudio it is

22、 automatically indented according to the current indentation options (see Customizing RStudio). R code is also re-indented: 假如你在RStudio中写R代码,她将自动依据目前缩进选项(见Customizing RStudio)进行缩进。R代码也可再缩进。1. Whenever new code is pasted into a source document. 2. When the Reindent Lines command (pictured above) is i

23、nvoked. 当新代码黏贴到一个source文件中;当缩进行命令(上图)被调用Note that RStudio automatic indentation is R syntax-aware and is therefore only used on source files containing R code.注意:RStudio自动缩进针正确是R语法意识,所以,只有在包含R代码source文件中使用Executing Code 实施代码RStudio supports the direct execution of code from within the source editor

24、(the executed commands are inserted into the console where their output also appears). RStudio支持从source编辑器中直接实施代码(实施代码将插入控制台,并在此输出结果),Executing a Single Line 实施一行代码To execute the line of source code where the cursor currently resides you press the Ctrl+Enter key (or use the Run toolbar button):你可经过C

25、trl+Enter键来实施目前光标所在行source代码(或使用Run工具条按钮)After executing the line of code, RStudio automatically advances the cursor to the next line. This enables you to single-step through a sequence of lines.实施完一行代码,RStudio自动将光标跳到下一行,这将使你能够在一系列行中单步实施代码。Executing Multiple Lines 实施多行代码There are three ways to execu

26、te multiple lines from within the editor:有三种方法从编辑器中实施多行代码。 Select the lines and press the Ctrl+Enter key (or use the Run toolbar button); or After executing a selection of code, use the Re-Run Previous Region command (or its associated toolbar button) to run the same selection again. Note that chang

27、es to the selection including additional, removal, and modification of lines will be reflected in this subsequent run of the selection. To run the entire document press the Ctrl+Shift+Enter key (or use the Source toolbar button). 选择这些行,按Ctrl+Enter键(或使用Run工具条按钮) 实施选择代码后,使用Re-Run Previous Region命令(或对应

28、工具栏按钮)再次运行相同选择。注意:现在发生改变,包含增增加、删除和修改行将反应到后续运行中。(或使用Ctrl+Shift+P快捷键) 运行整个文件按Ctrl+Shift+Enter键(或使用source工具条按钮)?The difference between running lines from a selection and invoking Source is that when running a selection all lines are inserted directly into the console whereas for Source the file is save

29、d to a temporary location and then sourced into the console from there (thereby creating less clutter in the console).从选择行进行运行和调用Source区分在于,当运行所选全部行将直接插入到控制台中,而对于Source文件则保留到临时位置然后从那里反应到控制台(所以在控制台中产生较少杂乱)。Source on Save 资源保留When editing re-usable functions (as opposed to freestanding lines of R) you

30、 may wish to set the Source on Save option for the document (available on the toolbar next to the Save icon). Enabling this option will cause the file to automatically be sourced into the global environment every time it is saved.当编辑一个再次调用函数(相对于独立R行而言),你可能期望对文件设置Source on Save选项(经过工具条中Save图标后一项实现)。启

31、用该选项造成文件每次保留全部将被全球自动采取。Setting Source on Save ensures that the copy of a function within the global environment is always in sync with its source, and also provides a good way to arrange for frequent syntax checking as you develop a function.设置Source on Save选项确保该函数版本在全球环境总是能够资源同时,而且也能在你开发一个函数是提供一个好方

32、法安排频繁语法检验。Keyboard Shortcuts 快捷键Beyond the keyboard shortcuts described above, there are a wide variety of other shortcuts available. Some of the more useful ones include:除了上述快捷键外,还有很多其它快捷键可用,其中最为有用快捷键包含。 Ctrl+Shift+N New document 新文档 Ctrl+O Open document 打开文档 Ctrl+S Save active document 保留活动文档 Ctrl

33、+1 Move focus to the Source Editor 移动焦点到Source编辑器 Ctrl+2 Move focus to the Console 移动焦点到控制台You can find a list of all shortcuts in the Keyboard Shortcuts article. Related Topics 相关专题 Working in the Console 在控制台中工作 Using Command History 使用历史命令 Navigating Code 代码导航 Code Folding and Sections 代码折叠和截取 Co

34、de Folding and Sections 代码折叠和截取Code Folding 代码折叠RStudio supports both automatic and user-defined folding for regions of code. Code folding allows you to easily show and hide blocks of code to make it easier to navigate your source file and focus on the coding task at hand. For example, in the follow

35、ing source file the body of the plot.autoregressive.model has been folded: RStudio支持自动和使用者定义地域代码折叠。代码折叠许可你很方便地显示和隐藏代码块,这将使你source文件导航更简易,并能够将中关键放在手头代码任务上。比如,在下面source文件中plot.autoregressive.model部分已经被折叠。You can expand the folded region by either clicking on the arrow in the gutter or on the icon that

36、 overlays the folded code. 你可展开折叠部分,经过点击箭头槽或覆盖折叠代码图标。Foldable Regions 折叠区域The following types of code regions are automatically foldable within RStudio: RStudio中以下类型代码区域将自动折叠: Braced regions (function definitions, conditional blocks, etc.) Code chunks within R Sweave or R Markdown documents Code sec

37、tions (see below for details) 支撑区域(函数定义、条件块等) R Sweave代码块或是RMarkdown文件。 代码段(具体见后文)In the following example you can see that the top-level code section, function body, and conditional blocks are all foldable: 在以下案例中,立即看到顶级代码部分、函数体和条件块全部被折叠。You can also fold an arbitrary selection of code by using Edi

38、t - Folding - Collapse (Alt-L). 你也可折叠任意选定代码,经过Edit - Folding - Collapse,或使用Alt-L快捷键。Folded regions are preserved while editing a document however when a file is closed and re-opened all foldable regions are by default shown expanded. 折叠部分在编辑文件时将被确保,不过当文件关闭或再次打开时,全部折叠部分将默认展开显示。Code Sections 代码段Code s

39、ections allow you to break a larger source file into a set of discrete regions for easy navigation between them. Code sections are automatically foldablefor example, the following source file has three sections (one expanded and the other two folded): 代码段许可你将一个大型source文件分解成一组独立区域以方便再她们之间漫游。代码段将自动折叠,

40、比如,以下源文件有三个部分(一个展开而另两个折叠)。To insert a new code section you can use the Code - Insert Section command. Alternatively, any comment line which includes at least four trailing dashes (-), equal signs (=), or pound signs (#) automatically creates a code section. For example, all of the following lines cr

41、eate code sections: 插入一个新代码段你使用Code - Insert Section命令。或,任意注释行中包含最少四个破折号(-),等号(=)或井号(#)将自动创建代码段。 # Section One - # Section Two = # Section Three # Note that as illustrated above the line can start any number of pound signs (#) so long as it ends with four or more -, =, or # characters. 注意:如前所述,可输入超出

42、4个或更多数量#号,-,=等。To navigate between code sections you can use the Jump To menu available at the bottom of the editor: 你可使用编辑器低端Jump To菜单在代码段间漫游(或使用Alt+Shift+J快捷键)。Menu Commands and Shortcuts 菜单命令和快捷键The following menu commands and shortcuts are available for working with folded regions and code secti

43、ons: 以下菜单命令和快捷键能够对折叠区域和代码段进行操作: Edit - Folding: Collapse Alt+L Expand Shift+Alt+L Collapse All Alt+A Expand All Shift+Alt+A Code: Insert Section Ctrl+Shift+R (Cmd+Shift+R on the Mac) Jump To Shift+Alt+J Note that the Collapse All command collapses all of the outermost foldable regions (rather than a

44、ll of the nested regions within the source file). 注意:Collapse All命令折叠全部外层可折叠区域(而不是源文件中全部嵌套区域)Related Topics Navigating Code 导航代码 Editing and Executing Code 编辑和实施代码Navigating Code 导航代码RStudio includes a number of features to enable rapid navigation through R source code. Learning these features can b

45、e a major productivity enhancement and can also assist in gaining a better understanding of source code written by others on your team or within external packages.RStudio包含部分在R源代码中加速导航功效。学习这些功效能够提升效率并帮助愈加好地了解你团体中其它人所写源代码,或是外部程序包中源代码。Find in Files 查找文件Given a specific directory, Find in Files allows

46、you to recursively search every file for each occurrence of a given string. To display the Find in Files dialog box, go to the edit menu and select Find in Files: 给出一个特定目录,查找文件(Edit-Find in Files)许可你对每个出现字符串递归查找每一个文件。显示查找文件对话框,编辑菜单并选择查找文件:You can further customize your search with regular expression

47、s and filters for specific file types. Your search results will display in the pane adjacent to the console. For each matching string, the following will be displayed: 你能够深入经过正式表示式和特定文件类型来自定义你搜索。你搜索结果将显示在控制台相邻窗口中。每一个匹配字符串全部将显示以下信息: The file path 文件路径 The line number of each occurrence 每个出现行号 The matching string (highlighted), in the context of the current line 目前行内容中匹配字符串(高亮)Double clicking the line, will open the file in the RStudio source editor

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 技术资料 > 其他杂项

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁