% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/webr-repl-links.R
\name{webr_repl_link}
\alias{webr_repl_link}
\title{Create a webR REPL sharelink from R code}
\usage{
webr_repl_link(
  input = NULL,
  filename = "script.R",
  path = NULL,
  autorun = FALSE,
  panels = NULL,
  version = "latest",
  base_url = NULL
)
}
\arguments{
\item{input}{Code input. Can be:
\itemize{
\item R expression (no quotes needed): \code{webr_repl_link({ plot(1:10) })}
\item Character string: R code to execute
\item File path: Path to R file to read
\item NULL: Read from clipboard (requires clipr package)
}}

\item{filename}{Name for the file (default: \code{"script.R"})}

\item{path}{Full path where the file will be placed in webR. If NULL (default),
the file is placed at \code{"/home/web_user/{filename}"}.}

\item{autorun}{Logical. Whether to auto-execute the code when link is opened (default: \code{FALSE}).
Only R files (\code{.R}) can be auto-executed.}

\item{panels}{Character vector or string specifying which webR interface panels to show.
Valid panels: \code{"plot"}, \code{"files"}, \code{"terminal"}, \code{"editor"}. Can be \code{c("plot", "files")} or \code{"plot-files"}.
If NULL (default), shows all panels.}

\item{version}{webR version to use (\code{"latest"} or specific version >= "v0.5.4")}

\item{base_url}{webR application URL. If NULL, uses global option or builds from version}
}
\value{
webr_link object containing the webR sharelink and metadata
}
\description{
Generates a shareable URL for R code that can be executed in the webR environment.
Supports expressions, file paths, character strings, and clipboard input.
}
\section{Comments in expression input}{

Expression input recovers your source from R's \emph{source references}, which R only
attaches when \code{keep.source} is enabled. Comments therefore survive in an
interactive session, but are dropped when the calling code is parsed without
source references -- notably inside a knitted 'Quarto' or 'R Markdown' document,
because 'knitr' evaluates chunks through \code{evaluate::evaluate()}, which discards
them. No \code{keep.source} setting recovers them there.

If you need comments preserved, pass the code as a string or a file path, or write
it as a chunk in the document -- see \link{livelink-knitr} and
\code{vignette("links-in-documents", package = "livelink")}.
}

\examples{
# Expression input (no quotes needed!)
webr_repl_link({
  plot(1:10)
  summary(mtcars)
})

# Traditional string input
webr_repl_link("plot(1:10)")

# Choose which panels the REPL shows
webr_repl_link({ hist(rnorm(100)) }, panels = c("plot", "editor"))

# Run the code as soon as the link opens
webr_repl_link("plot(1:10)", autorun = TRUE)

# File path input
script <- tempfile(fileext = ".R")
writeLines("plot(1:10)", script)
webr_repl_link(script)

# Read the code from the clipboard
if (interactive()) {
  webr_repl_link()
}
}
\seealso{
\code{\link[=webr_repl_project]{webr_repl_project()}} for multi-file projects and
\code{\link[=webr_repl_exercise]{webr_repl_exercise()}} for exercise and solution pairs; \link{livelink-knitr} to
give a document chunk its own link; \code{vignette("getting-started", package = "livelink")} for an introduction.
}
