Learn R Programming

misty (version 0.6.7)

script.new: 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.

Author

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

Run this code
if (FALSE) {

# 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)")
}

Run the code above in your browser using DataLab