Introduction to Writing Functions in R

Start Free Preview

Buying via our links supports this free directory · Affiliate disclosure.
Course facts
  • Payment: Free Preview (Paid Upgrade)
  • Learning style: Self-paced, start anytime
  • Format: Text & Interactive
  • Video access: Streaming Only
  • Before you start: Introduction to the Tidyverse; Intermediate R
DataCamp details
  • Chapters: 4
Created byDataCamp
Available onDataCamp

Course Details
Learning Style

Start Anytime

Level

Beginner

Study Mode

100% Online

Duration

Short (< 10 Hours)

Languages
Audio Language

English

Outcomes
Certificate

Certificate of Completion

Price & Terms
Pricing Model

Free Preview (Paid Upgrade)

Technical
Content Medium

Text & Interactive

Video Access

Streaming Only

Specification
Access

Subscription

SKU: introduction-writing-functions-r Category: Tags: , , Brand:

Learn to turn R scripts into reusable functions, set argument defaults, check inputs, return results and apply it all to a grain yield case study.

At a glance
Duration4 hrs
LevelBeginner
CertificateCertificate of Completion
LanguageEnglish
Taught byRichie Cotton
AccessSubscription
Add your review
Add to wishlistAdded to wishlistRemoved from wishlist 0
Add to compare

Writing functions in R lets an analyst package repeated script code under one name, so the work is easier to read, carries fewer errors and can move between projects. You decide which inputs a function takes and in what order, give them defaults, check what callers pass in, and choose what comes back. Later lessons look at how R finds a variable inside a function, and the final exercises apply these habits to agricultural grain yield data.

What You Will Achieve

  • Turn a block of repeated R script code into a function with clearly ordered inputs
  • Give arguments sensible defaults and stop a function with an informative error when inputs are wrong
  • Return several results from one function and predict which variable R will use inside it
  • Convert, plot and model a real dataset using functions you wrote yourself


Program Overview

Writing Functions and Their Arguments

Starts with why functions pay off and turns scripts into functions such as a coin toss, then sets argument defaults and checks.

  • Converting a script into a function
  • Ordering data and detail arguments
  • Numeric, logical, NULL and categorical defaults
  • Passing, checking and rejecting bad arguments

Return Values, Environments, and Scope

Looks at what a function hands back and how R decides which variables a function can see.

  • Early and invisible returns
  • Returning multiple values and metadata
  • Creating and exploring environments
  • Scope and variable precedence

Grain Yields Case Study

Applies the earlier chapters to grain yield data through data preparation, plotting and modeling steps.

  • Converting areas and yields to metric
  • Plotting yields over time by region
  • Running a model and making yield predictions

Certificate Awarded (Paid)


Job Outlook

Function writing in R is used wherever the same cleaning, plotting or modeling steps are repeated across datasets, as in data analysis, research and reporting work carried out in R.


Our take

Good for: R users who repeat the same analysis steps across projects and want to package that work as their own well-behaved functions.

Keep in mind: Practice centers on short exercises and one grain yield case study; applying the functions to your own data is left to you.

Bottom line: A focused grounding in R function design that gives real attention to argument checks, return values and variable scope.

Frequently Asked Questions

What data do the R exercises draw on?

The exercises draw on data about Wyoming tourism, stock price-to-earnings ratios and grain yields. The grain yield data carries the final chapter, where you convert units to metric, plot yields over time by region and fit a model.

How does the course handle variable scope in R?

One chapter looks at environments: how to create and explore them, how to check whether a variable exists, and which value R picks when the same name is defined both inside and outside a function.

What kinds of argument defaults are covered?

The lessons work through numeric, logical, NULL and categorical defaults, then show how to pass arguments on to other functions, including through the ... argument, and how to deal with missing values along the way.

User Reviews

0.0 out of 5
★★★★★
0
★★★★★
0
★★★★★
0
★★★★★
0
★★★★★
0

No reviews yet. Be the first to review this course.

There are no reviews yet.

Write your review

Reviews can only be posted by registered learners. Log in, then you will return here to post.

×

    Report this page
    Introduction to Writing Functions in R
    Introduction to Writing Functions in R
    LiveTalent
    Logo
    Compare items
    • Total (0)
    Compare
    0