0

I'm trying to use "sink" in a function in order to export my data in a text file but I'm struggling: I get an error message saying "argument "filename" is missing, with no default".

Could you help me? :)

That's my function:

Fonction_desc <- function(var_interest, g, titre, filename, myfun){
 
tab <- cbind("mean"= tapply(var_interest, g, mean), 
                 "sd"= tapply(var_interest, g, sd),
                 "min"= tapply(var_interest, g, min),
                 "max"= tapply(var_interest, g, max),
                  cat("====================================================================\n"))

cat("Statistiques par  mois  de la variable température\n")
 cat("--------------------------------------------------------------------\n")
     
 print(round(tab, digits = 2))
  
        sink(filename)
        
        sink()
   
tab
  }
 
Fonction_desc(meteo_charleroi$T, meteo_charleroi$date1, meteo_charleroi)

Kind regards :)

  • Your last line only passes 3 arguments to `Fonction_desc`. In the function definition, `filename` is the 4th argument, so it is reported as missing. – user2554330 Nov 02 '20 at 11:28
  • Yes, thank you it is working. I added a "character.txt" in my last line and now I'm able to export my data into a text file. However, my text file is empty, do you know why? Sorry, I started learning R 2 weeks ago and I need to practice. Thanks ! – Hugo Evrard Nov 02 '20 at 12:01
  • You are printing it before setting up the sink. – user2554330 Nov 02 '20 at 13:46

0 Answers0