Skip to content
Learn Netverks

Lesson

Step 31/36 86% through track

s3-s4-intro

S3 and S4 introduction

Last reviewed Jun 1, 2026 Content v20260601
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
advanced

This lesson

An orientation to the R track—how the compiled playground works, core vocabulary, and what you will practice next.

You need a clear map of the R track so vectors, data frames, factors, and the tidyverse mindset do not feel like magic.

You will apply S3 and S4 introduction in contexts like: Research pipelines, Shiny dashboards, and statistical reporting.

Write R in the editor and click Run on server—the dev runner executes with Rscript; use print() or cat() and base R in playground snippets (tidyverse locally; LEARNING_RUNNER_ENABLED=true). Also read the interview prep blocks.

After basic programming and ideally SQL—pair with Python for ML-heavy roles or stay in R for stats and research pipelines.

R's OOP systems: S3 generic functions (print, summary, plot) dispatch on class attributes; S4 formal classes for stricter contracts (Bioconductor).

S3 class

fit <- lm(y ~ x, data = data.frame(x = 1:3, y = c(1, 2, 2)))
print(class(fit))
print(summary(fit))

Generic functions

summary() behaves differently for lm, data.frame, and numeric—method dispatch via UseMethod internally.

Important interview questions and answers

  1. Q: S3 vs S4?
    A: S3 informal attributes; S4 slots and validity—S3 dominates base stats.
  2. Q: class() purpose?
    A: Returns class vector driving method dispatch and print formatting.

Self-check

  1. What does class(fit) show for lm?
  2. Name one S3 generic function.

Tip: summary(), print(), and plot() are S3 generics—behavior depends on class.

Interview prep

S3 generic example?

print, summary, plot dispatch on class.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • S3 method dispatch?
  • Use S4 when?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump