Skip to content
Back to skills

R Syntax

ASecurity

R syntax extensions and pipe operators. Use for magrittr pipes, functional programming, and syntax enhancements.

  • 5 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added June 4, 2026
datagodebugging

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned June 4, 2026

npx -y skills add LeoLin990405/r-analytics-skill --skill r-syntax --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of R Syntax?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for R Syntax
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/leolin990405-r-syntax/badge)](https://www.skillsdirectory.com/skills/leolin990405-r-syntax)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: r-syntax
description: R syntax extensions and pipe operators. Use for magrittr pipes, functional programming, and syntax enhancements.
---

# R Syntax Extensions

Pipe operators and syntax enhancements.

## magrittr Pipe

```r
library(magrittr)

# Basic pipe %>%
df %>%
  filter(x > 0) %>%
  select(a, b) %>%
  mutate(c = a + b)

# Equivalent to
mutate(select(filter(df, x > 0), a, b), c = a + b)
```

## Native Pipe (R 4.1+)

```r
# Native pipe |>
df |>
  filter(x > 0) |>
  select(a, b)

# With placeholder (R 4.2+)
df |> lm(y ~ x, data = _)
```

## magrittr Special Pipes

```r
# Assignment pipe %<>%
x %<>% sqrt()
# Equivalent to: x <- sqrt(x)

# Tee pipe %T>%
df %T>%
  print() %>%
  filter(x > 0)
# Prints df, then continues pipeline

# Exposition pipe %$%
df %$%
  cor(x, y)
# Exposes columns as variables
```

## Placeholder

```r
# Dot placeholder
df %>% lm(y ~ x, data = .)

# Multiple uses
df %>% {
  model <- lm(y ~ x, data = .)
  summary(.)
}

# In specific position
c(1, 2, 3) %>% paste("value:", .)
```

## Functional Sequences

```r
# Create reusable pipeline
my_pipeline <- . %>%
  filter(x > 0) %>%
  mutate(y = x * 2) %>%
  summarise(mean = mean(y))

# Apply to data
df1 %>% my_pipeline()
df2 %>% my_pipeline()
```

## Lambda Functions

```r
# Anonymous function in pipe
df %>%
  {function(d) d[d$x > 0, ]}() %>%
  head()

# With formula syntax (purrr)
df %>%
  map(~ .x * 2)
```

## Debugging Pipes

```r
# Print intermediate results
df %>%
  filter(x > 0) %>%
  print() %>%
  mutate(y = x * 2)

# Use browser
df %>%
  filter(x > 0) %>%
  {browser(); .} %>%
  mutate(y = x * 2)
```

## Best Practices

```r
# Good: Clear, readable pipeline
result <- df %>%
  filter(x > 0) %>%
  group_by(category) %>%
  summarise(mean = mean(value))

# Avoid: Too long pipelines
# Break into logical chunks
cleaned <- df %>%
  filter(x > 0) %>%
  mutate(y = log(x))

result <- cleaned %>%
  group_by(category) %>%
  summarise(mean = mean(y))

# Avoid: Side effects in pipes
# Use %T>% for side effects
df %T>%
  write.csv("output.csv") %>%
  summarise(n = n())
```

## Comparison

```r
# magrittr %>%
# - Works with any function
# - Dot placeholder
# - Special pipes (%<>%, %T>%, %$%)

# Native |>
# - Faster (no function call overhead)
# - Built into R
# - Limited placeholder support
# - No special pipes
```

Files in this skill

  • SKILL.md2.3 KB
  • magrittr/SKILL.md2.6 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.