InseadDataAnalytics / INSEADAnalytics

Other
122 stars 1.31k forks source link

getting issues with using the setwd command #156

Open MinhasMA opened 6 years ago

MinhasMA commented 6 years ago

Can someone comment on the setwd() command in R? Seemingly have followed the correct syntax, but keep on getting an error setwd("Addresstoworkingdirectory")

VarunKShetty commented 6 years ago

What is the error you get?

MinhasMA commented 6 years ago

Was able to figure it out. Thanks!

MinhasMA commented 6 years ago

However, there is another issue

Quitting from lines 58-69 (MarketSegmentationProcessInClassParts1and2.Rmd) Error in file(filename, "r", encoding = encoding) : cannot open the connection

rmarkdown::render("MarketSegmentationProcessInClassParts1and2.Rmd")

processing file: MarketSegmentationProcessInClassParts1and2.Rmd |. | 2% ordinary text without R code

|.. | 4% label: setuplibraries (with options) List of 2 $ echo : logi FALSE $ message: logi FALSE

Quitting from lines 58-69 (MarketSegmentationProcessInClassParts1and2.Rmd) Error in file(filename, "r", encoding = encoding) : cannot open the connection

VarunKShetty commented 6 years ago

What are the lines 58 - 69 in your RMD file?

MinhasMA commented 6 years ago
suppressWarnings(source("../../AnalyticsLibraries/library.R"))
# Package options
suppressWarnings(ggthemr('fresh'))  # ggplot theme
opts_knit$set(progress=FALSE, verbose=FALSE)
opts_chunk$set(echo=FALSE, fig.align="center", fig.width=10, fig.height=6.35, results="asis")
options(knitr.kable.NA = '')

# Run below only once, then comment out
# New versions of the networkD3 package may not work properly, so install the following version
packageurl <- "https://cran.r-project.org/src/contrib/Archive/networkD3/networkD3_0.2.13.tar.gz"
install.packages(packageurl, repos=NULL, type="source")


\clearpage

MinhasMA commented 6 years ago

I have the correct directory as set by setwd() But it appears that some information was lost in translation?

VarunKShetty commented 6 years ago

"../../AnalyticsLibraries/library.R" is a relative path. This basically says, go up two levels from the working directorry and look for a folder called "AnalyticsLibraries" at that location. Does that process make sense in your context? If not, subsitute the ../../AnalyticsLibraries/library.R with the absolute path. For example: In my case: Users/Varun/Docs/InseadAnalysticsGit/AnalyticLibraries/Library.R

MinhasMA commented 6 years ago

Tried it but it did not work. I looked at the folder and the analyticslibraries folder is not present in my home folder (setwd)

Could I comment out the whole section? 58-69?

VarunKShetty commented 6 years ago

No. Don't comment it out. The RMD needs that piece for knitting.

Do you have the Library.R script on your disk somewhere? What is the path to that file?

MinhasMA commented 6 years ago

Yes, file is available on my computer.

I've made the following address change (locating it to the right folder)

Still get an error

suppressWarnings(source("C:\Users\manna\Documents\COURSES\Data Science for Business\INSEADAnalytics-master\INSEADAnalytics-master\CourseSessions\Session1 /AnalyticsLibraries/library.R"))

VarunKShetty commented 6 years ago

Can you try this instead? I just replaced with appropriate slashes. C:/Users/manna/Documents/COURSES/Data Science for Business/INSEADAnalytics-master/INSEADAnalytics-master/CourseSessions/Session1/AnalyticsLibraries/library.R

MinhasMA commented 6 years ago

Tried and it still fails :(

Quitting from lines 58-71 (MarketSegmentationProcessInClassParts1and2.Rmd) Error in file(filename, "r", encoding = encoding) : cannot open the connection

Lines 58-71

suppressWarnings(source("C:/Users/manna/Documents/COURSES/Data Science for Business/INSEADAnalytics-master/INSEADAnalytics-master/CourseSessions/Session1/AnalyticsLibraries/library.R"))

# Package options
suppressWarnings(ggthemr('fresh'))  # ggplot theme
opts_knit$set(progress=FALSE, verbose=FALSE)
opts_chunk$set(echo=FALSE, fig.align="center", fig.width=10, fig.height=6.35, results="asis")
options(knitr.kable.NA = '')

# Run below only once, then comment out
# New versions of the networkD3 package may not work properly, so install the following version
packageurl <- "https://cran.r-project.org/src/contrib/Archive/networkD3/networkD3_0.2.13.tar.gz"
install.packages(packageurl, repos=NULL, type="source")
VarunKShetty commented 6 years ago

Are you sure your path is correct? You should be routing to the library.R inside AnalyticsLibraries. There isn't an AnalyticsLibraries folder inside Session1 typically.

VarunKShetty commented 6 years ago

"C:/Users/manna/Documents/COURSES/Data Science for Business/INSEADAnalytics-master/INSEADAnalytics-master/AnalyticsLibraries/library.R" "C:/Users/manna/Documents/COURSES/Data Science for Business/INSEADAnalytics-master/AnalyticsLibraries/library.R" I think your correct path should be one of the above two.

MinhasMA commented 6 years ago

Thanks a lot. It works!