script.new: Open new R Script, R Markdown script, or SQL Script in...

View source: R/script.new.R

script.newR Documentation

Open new R Script, R Markdown script, or SQL Script in RStudio

Description

This function opens a new R script, R markdown script, or SQL script in RStudio.

Usage

script.new(text = "", type = c("r", "rmarkdown", "sql"),
           position = rstudioapi::document_position(0, 0),
           run = FALSE, check = TRUE)

Arguments

text

a character vector indicating what text should be inserted in the new R script. By default, an empty script is opened.

type

a character string indicating the type of document to be created, i.e., r (default) for an R script, rmakrdown for an R Markdown file, or sql for an SQL script.

position

document_position() function in the rstudioapi package indicating the cursor position.

run

logical: if TRUE, the code is executed after the document is created.

check

logical: if TRUE (default), argument specification is checked.

Note

This function uses the documentNew() function in the rstudioapi package by Kevin Ushey, JJ Allaire, Hadley Wickham, and Gary Ritchie (2023).

Author(s)

Takuya Yanagida takuya.yanagida@univie.ac.at

References

Ushey, K., Allaire, J., Wickham, H., & Ritchie, G. (2023). rstudioapi: Safely access the RStudio API. R package version 0.15.0 https://CRAN.R-project.org/package=rstudioapi

See Also

script.close, script.open, script.save, script.copy, setsource

Examples

## Not run: 

# Example 1: Open new R script file
script.new()

# Example 2: Open new R script file and run some code
script.new("#----------------------------
# Example

# Generate 100 random numbers
rnorm(100)")

## End(Not run)

misty documentation built on June 29, 2024, 9:07 a.m.

Related to script.new in misty...