2

I'm working with R for some analysis, back at university I used to save my R script to a file without the output with notes in it.

I can't remember the command anymore! It was of the kind open to start printing to a file and close the printing when the work was done. This was very useful as I could separate the chuncks of commands, save in different files, only save what I needed, etc...

Here's an example of the output (.txt file)

df <- read.table ("albu_828614.txt", header = TRUE, na.strings = "NA")
str(df)
dim(df)

###################################
#       Question      #
###################################

###########
# Summary #
###########

summary (df[-c(5,6,7)]) # Summary of numerical variables

length(df$NE[df$NE == "1"])
length(df$COR[df$COR == "1"])
length(df$CUST[df$CUST == "1"])

#summary of categorical variables: number of variables 1 in each category

It is not the save history option, which saves every command in the console, as I could decide when to start and stop writing the file.

zx8754
  • 52,746
  • 12
  • 114
  • 209
Flo
  • 21
  • 4
  • 2
    See `?sink`, looks like a duplicate for this post: http://stackoverflow.com/questions/7096989 – zx8754 Jan 17 '17 at 12:30
  • 2
    I'm afraid it's not the same case, the user there is asking to save both input and output. In my case, I'd like to save input without output, and selectively to a file (so the savehistory command is not what I'm looking for) – Flo Jan 17 '17 at 12:57
  • Not exactly what you are looking for, but the `history()` command allows you to specific the number of previous commands and a file to save to, e.g. `history(file='myscript.R', max.show=10)` – Keith Hughitt Jan 17 '17 at 13:43
  • 1
    Why not use RStudio and type your commands and comments into Source straight away? Rather than working with console itself. It also allows you quick look at your history of commands typed in console, select the ones you want to save or delete. – Jav Jan 17 '17 at 14:03
  • @Jav thank you that's a good idea! I didn't know RStudio, I've always used just R! – Flo Jan 17 '17 at 14:09

0 Answers0