getting started with rstudio

92 223 0
getting started with rstudio

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

www.it-ebooks.info www.it-ebooks.info Getting Started with RStudio John Verzani Beijing • Cambridge • Farnham • Köln • Sebastopol • Tokyo www.it-ebooks.info Getting Started with RStudio by John Verzani Copyright © 2011 John Verzani. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com. Editor: Mike Loukides Production Editor: Kristen Borg Proofreader: O’Reilly Production Services Cover Designer: Karen Montgomery Interior Designer: David Futato Illustrator: Robert Romano Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Getting Started with RStudio, the image of a ribbonfish, and related trade dress are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information con- tained herein. ISBN: 978-1-449-30903-9 [LSI] 1316092792 www.it-ebooks.info Table of Contents Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v 1. Overview, Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 What is R? 1 What is an IDE? 2 Why RStudio? 3 Using RStudio 4 Desktop Version 4 Server Version 5 Which Workspace? 7 Projects 7 Which R? 7 Layout of the Components 8 Keyboard Shortcuts 8 The Options Dialog 9 Installing RStudio 9 Updating RStudio 11 2. Case Study: Data Cleaning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Using Projects 14 Reading in a Data File 14 Tab Key Completion 16 Workspace Component 18 Using the Right Class to Store Data 19 Data Cleaning 20 Using the Code Editor to Write R Scripts 21 Using Add-On Packages 22 Graphics 23 Command History 24 All Finished, for Now 25 iii www.it-ebooks.info 3. The Console and Related Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Entering Commands 27 Automatic Insertion of Matching Pairs 29 R Script Files 29 Command-Line Conveniences 31 Tab Completion 31 Keyboard Shortcuts 34 Command History 36 Workspace Browser 38 Editing and Viewing Objects 39 Importing Data Sets 41 The Help Page Viewer 42 The Browser 45 The Plots Browser 46 Interactivity 48 The manipulate Package for RStudio 48 External Programs (Desktop Version) 50 4. Case Study: Creating a Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Creating Functions from Script Files 52 A Package Skeleton 52 Documenting Functions with roxygen2 56 The devtools Package 57 Package Data 59 Package Examples 60 Adding Tests 60 Building and Installing the Package 60 5. Programming R with RStudio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Source Code Editor 63 Basics 64 R Programming Features 67 Navigation 70 The File Browser 71 Debugging R Code in RStudio 72 Package Maintenance 73 Case Study: Report Generation 75 iv | Table of Contents www.it-ebooks.info Preface Conventions Used in This Book The following typographical conventions are used in this book: Italic Indicates new terms, URLs, email addresses, filenames, and file extensions. Constant width Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords. Constant width bold Shows commands or other text that should be typed literally by the user. Constant width italic Shows text that should be replaced with user-supplied values or by values deter- mined by context. This icon signifies a tip, suggestion, or general note. This icon indicates a warning or caution. v www.it-ebooks.info Using Code Examples This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission. We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “Getting Started with RStudio by John Ver- zani (O'Reilly). Copyright 2011 John Verzani, 978-1-449-30903-9.” If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at permissions@oreilly.com. Safari® Books Online Safari Books Online is an on-demand digital library that lets you easily search over 7,500 technology and creative reference books and videos to find the answers you need quickly. With a subscription, you can read any page and watch any video from our library online. Read books on your cell phone and mobile devices. Access new titles before they are available for print, and get exclusive access to manuscripts in development and post feedback for the authors. Copy and paste code samples, organize your favorites, down- load chapters, bookmark key sections, create notes, print out pages, and benefit from tons of other time-saving features. O’Reilly Media has uploaded this book to the Safari Books Online service. To have full digital access to this book and others on similar topics from O’Reilly and other pub- lishers, sign up for free at http://my.safaribooksonline.com. How to Contact Us Please address comments and questions concerning this book to the publisher: O’Reilly Media, Inc. 1005 Gravenstein Highway North Sebastopol, CA 95472 800-998-9938 (in the United States or Canada) 707-829-0515 (international or local) 707-829-0104 (fax) vi | Preface www.it-ebooks.info We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at: http://shop.oreilly.com/product/0636920021278.do To comment or ask technical questions about this book, send email to: bookquestions@oreilly.com For more information about our books, courses, conferences, and news, see our website at http://www.oreilly.com. Find us on Facebook: http://facebook.com/oreilly Follow us on Twitter: http://twitter.com/oreillymedia Watch us on YouTube: http://www.youtube.com/oreillymedia Preface | vii www.it-ebooks.info www.it-ebooks.info [...]... interfaces with R through the rJava and JRI packages The Deducer package adds a suite of data analysis tools Tinn-R Windows An extension for the Tinn editor that allows integration with an underlying R process Notepad++ Windows With the NpptoR extension allows the Notepad++ editor to interact with an R process RGui Windows The Windows GUI for R has many of the features of an IDE Why RStudio? The RStudio. .. (https://github.com /rstudio/ rstudio) RStudio is built on top of many other open-source projects Most visible of these are GWT, Google’s Web Toolkit; Qt, the graphical toolkit of Nokia; and Ace, the JavaScript code editor (http://ace.ajax.org) Other leveraged projects are listed in RStudio s About dialog The bulk of the code is written in C++ and Java, the language for working with GWT Using RStudio We will... things slightly by beginning with the process of starting RStudio, and postpone any installation issues for a bit As RStudio can be used from the desktop or through a server, there are two ways of starting it Desktop Version For the desktop version, RStudio is started like most other applications In Figure 1-1, we see the application running under Mac OS X There it was started by clicking on its icon... Settings\Application Data \RStudio- Desktop\log for XP In the application’s menu bar, the Help > Diagnostics item can be used to find the log files Updating RStudio Updating RStudio is also straightforward To see if an update is available, the Help > Check for Updates menu item will open a dialog with update information If an update is available, one can stop RStudio, install the new version, then restart RStudio writes... https://github.com /rstudio/ rstudio Installation details are in the INSTALL file accompanying the source code The same source is used to compile both the Desktop and Server version 10 | Chapter 1: Overview, Installation www.it-ebooks.info As RStudio depends on some of the latest features of many moving parts, such as GWT, there can be issues with compiling from the source The support forums (http://support .rstudio. org/)... ~/ .rstudio- desktop) This will persist between upgrades Installing RStudio | 11 www.it-ebooks.info www.it-ebooks.info CHAPTER 2 Case Study: Data Cleaning Now that we know how to start RStudio, let’s dive in We’ll begin with a blow-by-blow account of a sample data analysis for which we read in some data, clean it up, then format it for further study The point of the exercise is to show how many of RStudio s... examples of panel placement on http:/ /rstudio. org/screenshots/ The appearance panel of the options dialog allows one to set the default font size and modify the theme for the editing in the console or source-code editor This book uses the default TextMate theme for its screenshots Installing RStudio Installing RStudio is usually a straightforward process First, RStudio requires a working, relatively... Applications folder For Windows users, the installation process leaves a menu item For Linux users, the command rstudio will open the window It may also be installed with a menu item, as is done with Ubuntu, where it appears under Programming 4 | Chapter 1: Overview, Installation www.it-ebooks.info Figure 1-1 RStudio on initial startup; the main interface has four panels (one hidden in this screenshot), a toolbar,... system—detached from the application and at the top of the screen —and is not integrated into the RStudio GUI For the server version, the menu bar appears above the application’s main toolbar Using RStudio | 5 www.it-ebooks.info Figure 1-2 Login screen for the server version of RStudio Figure 1-3 Screenshot of RStudio startup run through a web browser; here, the Source component is hidden, as no files are... (0.94.102) but is in the “daily build” version Which R? RStudio does not require a special version of R to run, as long as it is a fairly modern one It will work with binary versions from CRAN or user-compiled versions As such, when RStudio starts up, it must be able to locate a version of R, which could possibly reside in many different places Usually RStudio just finds the right one, but one can bypass . www.it-ebooks.info www.it-ebooks.info Getting Started with RStudio John Verzani Beijing • Cambridge • Farnham • Köln • Sebastopol • Tokyo www.it-ebooks.info Getting Started with RStudio by John Verzani Copyright. Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Getting Started with RStudio, the image of a ribbonfish, and related trade dress are trademarks of O’Reilly. An attribution usually includes the title, author, publisher, and ISBN. For example: Getting Started with RStudio by John Ver- zani (O'Reilly). Copyright 2011 John Verzani, 978-1-449-30903-9.” If

Ngày đăng: 28/04/2014, 16:02

Mục lục

  • Preface

    • Conventions Used in This Book

    • How to Contact Us

    • Chapter 1. Overview, Installation

      • What is R?

      • What is an IDE?

      • Layout of the Components

        • Keyboard Shortcuts

        • Chapter 2. Case Study: Data Cleaning

          • Using Projects

          • Reading in a Data File

          • Workspace Component

            • Using the Right Class to Store Data

            • Using the Code Editor to Write R Scripts

            • All Finished, for Now

            • Chapter 3. The Console and Related Components

              • Entering Commands

                • Automatic Insertion of Matching Pairs

                • Command History

                  • Searching the history stack

                  • Workspace Browser

                    • Editing and Viewing Objects

                    • The Help Page Viewer

                    • The Browser

                      • The Plots Browser

                      • The manipulate Package for RStudio

                      • External Programs (Desktop Version)

                      • Chapter 4. Case Study: Creating a Package

                        • Creating Functions from Script Files

                        • Documenting Functions with roxygen2

                        • Building and Installing the Package

Tài liệu cùng người dùng

Tài liệu liên quan