InseadDataAnalytics / INSEADAnalytics

Other
122 stars 1.31k forks source link

Rmarkdown error #147

Open tomassilveira opened 6 years ago

tomassilveira commented 6 years ago

Hi everyone,

I am trying to run an rmarkdown document similar to the one we did on clustering but get the following error :

rmarkdown::render("INSEADAnalytics-master/INSEADAnalytics-master/CourseSessions/Homicides_project/Final_Project_v2TS.Rmd") processing file: Final_Project_v2TS.Rmd Installing package into 'C:/Users/tomas/Documents/R/win-library/3.5' (as 'lib' is unspecified) trying URL 'https://cran.r-project.org/src/contrib/Archive/networkD3/networkD3_0.2.13.tar.gz' Content type 'application/x-gzip' length 107647 bytes (105 KB) downloaded 105 KB

2: In block_exec(params) : failed to tidy R code in chunk reason: Error in loadNamespace(name) : there is no package called 'formatR'

Anyone had the same issue/would be willing to help?

Tomas

tomassilveira commented 6 years ago

The error seems to be coming from this line of code :

iprint.df(round(my_summary(ProjectDataFactor), 2))

Antoine-Engerand commented 6 years ago

Hi Tomas. Maybe this website can help for the tidy R error: https://yihui.name/formatr/ For the first one, there may be NA or NaN values in your data. That's what the message seems to indicate. I hope it helps! ;)

tomassilveira commented 6 years ago

Thank you Antoine! Indeed, there was a problem with some NA values. Slowly progressing :)

cynthiadandrea commented 6 years ago

I am also trying to do the same thing, but am getting a different style of error: "Error in quantile.default(r, 0.25) : missing values and NaN's not allowed if 'na.rm' is FALSE "

tomassilveira commented 6 years ago

Seems to be in the same line you are having a problem, and also due to NA values.

Have you checked the ProjectData_Initial file to see if you have any NAs?

cynthiadandrea commented 6 years ago

I do. I tried using the below to fix it, but it doesnt seem to work. fixNAs<-function(data_frame){

Define reactions to NAs

integer_reac<-0 factor_reac<-"FIXED_NA" character_reac<-"FIXED_NA" date_reac<-as.Date("1900-01-01")

tomassilveira commented 6 years ago

Here is how we did. Perhaps it will work with you :

rawdata$Perpetrator.Age[rawdata$Perpetrator.Age=="NA"] = 0 rawdata$Victim.Age[rawdata$Victim.Age=="NA"] = 0 rawdata$Victim.Age[rawdata$Victim.Age=="NA"] = 0

The first line for instance is basically saying : if column Perpetrator.Age in rawdata is equal to "NA", then turn it equal to 0. With just one line you solve the problem of an entire column