R comment remover

Remove comments from
R code.

Remove comments from R scripts and notebooks online. Handles `#` line comments while preserving string literals and roxygen2-style headers.

Free, no signup Runs in your browser Instant, no upload Works on .r files

Before and after

Real-world R code on the left. The same code with every comment removed on the right.

r-input.r
# Customer churn analysis
library(dplyr) # data manipulation
library(ggplot2) # plotting

# Load the data
df <- read.csv("customers.csv") # one row per customer

# Filter inactive
df <- df %>% filter(active == TRUE) # only active rows

# Compute churn rate
churn <- df %>%
  group_by(plan) %>% # by plan
  summarise(rate = mean(churned)) # mean churn

# Plot it
ggplot(churn, aes(x = plan, y = rate)) +
  geom_col() +
  labs(title = "Churn rate by plan") # main title
r-output.rcleaned
library(dplyr)
library(ggplot2)

df <- read.csv("customers.csv")

df <- df %>% filter(active == TRUE)

churn <- df %>%
  group_by(plan) %>%
  summarise(rate = mean(churned))

ggplot(churn, aes(x = plan, y = rate)) +
  geom_col() +
  labs(title = "Churn rate by plan")
Why use it

Built for R specifically.

R scripts for analysis, modeling, and reporting tend to carry running commentary, explanations of statistical choices, references to papers, alternative parameterizations. When you want to share a tidy reproducible example or generate an executive-friendly version of a notebook, removing the running commentary is the fastest path. Uncommenter handles R's `#` line-comment syntax cleanly.

  • # line comments removed
  • Single and double-quoted strings preserved
  • Function definitions and pipe operators (|>, %>%) untouched
  • Roxygen2 #' headers also removed (treated as line comments)
  • Auto-detected from .r, .R, and .rmd files
How it works

Strip comments in 30 seconds.

  1. 1

    Open the tool

    Head to uncommenter.com/tool. Nothing to install. Nothing to sign up for.

  2. 2

    Paste your R code

    Drop your .r file in, or paste code into the editor. Auto-detection picks up R from the extension or file content.

  3. 3

    Click 'Remove Comments'

    The parser walks every character with a real state machine, strings, regex, and other context-sensitive parts are detected and left alone.

  4. 4

    Copy or download

    Grab the cleaned output. Your code never left your browser.

FAQ

R questions, answered.

Does it work on R Markdown (.rmd) files?

+

It strips R-style # comments. R Markdown has additional Markdown and chunk-header syntax that the parser leaves untouched, but it won't strip Markdown-level <!-- --> comments, pipe those through the HTML page.

What about strings containing #?

+

String literals are tracked, so "#hex" or 'a #string' is left alone.

Will it remove roxygen2 doc headers?

+

Yes. #' lines are line comments to R, so they're removed along with regular #. If you want them kept, run the tool only on already-built code.

Other languages

Working in something else?

Plus 35+ more languages supported in the live tool , including HTML, YAML, Dockerfile, Terraform, Solidity, and more.

Try it on your R code now.

Free forever. No signup. No upload. Runs entirely in your browser.

Open uncommenter