Input and output

2016/02/05

Input and output

The source-function runs a script in the current session. If the filename does not include a path, current workind directory (cwd) is assumed. Input a script:

source("myfile")

Sink-function defines the direction of the output. The append option controls whether output overwriter or adds to a file. The split option determines if output is also sent to the screen as well as the output file.

sink("myfile.txt", append=FALSE, split=FALSE)

#return output to the terminal
sink()

sink("output.txt")

Output to jpeg-file.

# Data to plot
x <- c(1,2,3)
# Define output
jpeg("myplot.jpg")
# Plot picture
plot(x)
# Turn off output
dev.off()

# Other graphic outputs:
pdf()
png()
bmp()
postscript()