Opens a file using the system's default application in a cross-platform manner. Works on Windows, macOS, and Linux.

open_file(path)

Arguments

path

A character string specifying the path to the file to open.

Value

Invisible NULL. The function is called for its side effect of opening a file.

Details

This function detects the operating system and uses the appropriate command to open the file:

  • Windows: Uses shell.exec()

  • macOS: Uses system2("open", ...)

  • Linux: Uses system2("xdg-open", ...)

Examples

if (FALSE) { # \dontrun{
# Open a PDF file
open_file("path/to/document.pdf")

# Open an Excel file
open_file("path/to/spreadsheet.xlsx")

# Open a PNG image
open_file("path/to/image.png")
} # }