GitHub Website Publishing of "Knit"-Generated HTML files in RStudio - html

I want to share a step-by-step illustration on how to publish online your work on RStudio using GitHub pages.
A lot of people taking the Coursera courses on data have problems with it if they don't come from computer science, including myself, so I want to share a system that works. I'm sure it can be greatly improved.

Let's do it step-by-step, really easy:
1. Start with Github, not with RStudio.
Don't have an account, sign-up for one - it's free and incredibly valuable. Now go to Repositories (top menu bar), and press on the green button New in the upper-right-hand corner. Give a name to the repository ("test" for our puposes). You can skip the Description if you are in a hurry to proving to yourself that it works (same for the prompt to write some memo style one-liner under README). So go... click on Create Repository (green button). Now don't panic... just go directly to Settings (the cogwheel symbol in the vertical menu on the right-hand side). Perfect! One more click and we're there... Launch automatic page generator. Now we enter the guided part. Feel free to leave all this as is for now... We can modify it later, or we can go back and do it all over again when we know the end of the story (with a real repository that we do intend to publish. Click on Continue to layouts. Click on any of the designs (I chose "Architect)... And Publish page (green button upper-right corner). Beautiful!
Quick check: Click on Settings again, and check under GitHub Pages for the message: "Your site is published at http://...github.io/test. In my case the address is http://rinterested.github.io/test/ (was... I erased it after I finished this post) beacuse my Github account is RInterested. Very critical: pay attention to the structure: github.io without this there's no website. Now you can go to your browser, type the address and see that a new site has been born (caution: sometimes this takes minutes to materialize).
2. Now it's time to go to RStudio. If you're taking the Coursera course this is your comfort zone. If not I will assume that you've been working with [R], and that a simple download of RStudio (free online) is about to change your life for the better.
So we start RStudio and we go to the upper-right corner, where there is a cube containing an R, and the word Project. See it? Great, because we are going to start a New Project from the pull-down menu. Pop-up... which one to choose? Version Control is the answer. More pop-ups... No panicking... Click on the gray/red/green sideways GIT symbol ("Git Clone a project from a Git repository"). We have that, remember? We called it "Test". And we are facing a final screen with three fields to fill in. Under Repository URL we need to enter information that will require a quick trip back to Github for a second...
Are you there? OK... Do you see the HTTPS clone URL thing with a clipboard symbol on the right, half-way down within the test repository? Click on the clipboard symbol... Copied! Great! Now we go back to the screen with questions on RStudio, where we got re-routed, and do a right-click and paste, filling in the Repository URL field of the questionnaire. The rest is not critical. Press on Create Project... That's it!
3. Time to work. Let's now create a new R Markdown document by clicking on the corresponding option on the pull-down menu in the left-upper corner (green plus sign on a sheet of paper icon). Give it a name. You are the author. Select HTML. Click OK. Now you can modify, add, or just leave what popped-up on the screen as is to finish up the demonstration. Notice that there are so-called chunks of code started with ``{r} which indicate that the following code will be executed upon rendering the html document (or pdf). echo=FALSE means that only the result of the code (not the actual command) will be printed.
OK. Press on the top menu where you see a knitting pin (Knit HTML)... give it a name and save the document... Very important... whatever you name it it has to end up in .Rmd (case sensitive). What about "cars.Rmd"? Original enough... Save it and watch RStudio do its magic... Hopefully you're now admiring a beautiful webpage with a plot and numbers... Only one problem... It is NOT online.
4. Pushing our work to GitHub:
We are going now in the opposite direction. First, click on the GiT super-cool symbol on the top menu (above "knit HTML" depending on the configuration of your RStudio). It's a pull-down menu. Select Commit. You can select cars.html, or everything. Disregard a warning message, and post an ultra-short note under "Commit message". Whatever you want to write (e.g. "update"?). Click on the Commit button - very important! Now you are ready to click on Push... You guessed it... It's the green button. You will be prompted to enter your Github account Username and Password. Do so.
5. Back to GitHub:
Refresh the page displaying our "test" repository. You should now see the additional documents, including cars.html
Quick check: Go to your browser and enter in the URL bar what for me would be rinterested.github.io/test/cars.html (remember that you can get your own website address by going under Settings as explained above), and then just tag on the name of the document we have worked on with RStudio.
6. Hyperlink the pages:
As a test click on "index.html" under the "test" repository and somewhere there, in the body embed the following:
Click here to go to cars.
You will have to click on the pencil icon to edit this file. When done click on Commit changes. Go back on the browser to see your site. Refresh until it's updated with the hyperlink you just embedded. Click on it... You are now watching your RStudio work fully functional online. Magic!
Now it's just a matter to change things around using some html code quickly accessible online, changing the wording on the index.html (home page), or perhaps building a nice site with internal cohesiveness from scratch.
Good luck!

An alternative (more manual) approach - anything covered on the initial answer skipped.
1. Create a Repository in GitHub
Let's call it Course_project without need to README - we're just going to need its URL.
2. Open Windows PowerShell (or Git Bash)
Opening Git Bash is as simple as to right click on the directory in Windows Explorer we want to select, and click on Git Bash here. I'll use PowerShell. You can get the directory you're in by typing pwd. From there we can type ls to list subfolders, all along changing directory to reach where we want to be - for instance cd R to get R as the working directory.
Clone project by typing https://github.com/RInterested/Course_project.git (I am RInterested, so change that part to your GitHub username; also remember that "Course_project" is the name of this project). Change the directory to Course_project by typing cd Course_project. We now create a branch without parent branches: git checkout --orphan gh-pages. Make sure that the cloned Course_project is empty by typing: git rm -rf . We'll soon work with real RStudio markdown, but just to test what we have done so far, we can type into the empty working directory a name of a webpage: echo "Test Page" > index.html. Time now to Add/Commit/Push: git add index.html followed by git git commit -a -m "first commit", and git push origin gh-pages. This page is now visible at: http://RInterested.github.io/Course_project/index.html.
3. Creating content with RStudio
We have a directory (Course_project) and a toy index.html in it... We need real content. So we go to RStudio. Create an R Markdown file and name it (I'm calling it mtcars). Check HTML as the output. Change the document (some info about it in the answer above). Finally, an important step: Save it as Index.Rmd(make sure that the R working directory is the same as in PowerShell). Click on knit HTML to create the html file rendering the R code embedded in R Markdown.
4. Pushing it upstream with PowerShell
Now we have material within the directory Course_project, but it is not online - it is still local (you can go to it with Windows Explorer and see the html file under "index"). Type git status to see the changes made, and again follow the routine Add/Commit/Push: git add ., followed by git commit -a -m "commit", and git push origin gh-pages.
After a while the page will be live in http://RInterested.github.io/Course_project/index.html
5. Adding a second page
We can now start a second R Markdown file on RStudio (I labeled it Second_page and saved it as Second_page.Rmd. After writing what we want we knit HTML, and we can see these two new files appear in the Course_project local folder. We simply have to Add/Commit/Push like before in PowerShell. The new page will be in http://rinterested.github.io/Course_project/Second_page.html. It is very easy now to type a hyperlink on the first (index.Rmd) to the second (Second_page.html), knit the index.Rmd, and push it up to the web.

Related

How to add a repository in Git Hub?

Please give the steps to follow
I tried to upload my zip files of HTML project and my repository is still empty. My repository is still empty after trying to upload.
Go to profile at the top right of the page in github and then go to the your repositories option. Then select new, and enter the name and then if want to write the code or you can add the files and click create.

How can I configure sublime to always open to the same folder?

I have a folder that I want Sublime to always open to ...
my_folder
Is there somewhere I can set this so that when ever I click on the Sublime Icon it opens to this folder?
For some reason if I manually quit sublime text through the menu it will open my last folder on re-opening.
However, if I just click the close X button, it will not ... it will open a blank window.
Is there somewhere I can set this correctly in the JSON file?
Well not sure if you are aware of it, but ST has a quick switch project (usually ctrl+alt+p) that will show you your recently opened projects.
Of course it has its own drawbacks:
Unable to remove one instance from it without removing all (clear recent projects cache)Can’t open the project in a new window… instead it only replaces the current project
But AFAIK this would be the most optimal way to work with multiple projects. you just need to go to the folder of the desired project and open it once and it will be available as recent project in the future…
The point of having to choose where to save the project file, IMO is because you may want to share the same file with other people or just have them wherever you want… maybe having all in one place is good for you (it is for me as well) but other people might like to have it in separate folders. 
I usually work with the project replace window… or just go in “Project -> Open recent -> …” which opens a new ST window for me!
Hope this helps you

How to start Sublime Text with selected project using a local .sublime-project file?

I may be missing the obvious, but can't seem to solve this fairly simple & typical case (with v3 build 3022 on Debian or XP, in case it matters):
Start Sublime Text opening a project "myprj", specified on its command-line,
using default.sublime-project located under that project's dir (say "/repo/myprj"),
automatically re-opening the last open files of that project (i.e. its workspace),
using default.sublime-workspace for that (also from the same project dir)
but (obviously) not auto-opening any other files remembered from non-project sessions,
and automatically saving all open files (to the above default.sublime-workspace) on exit.
Ideally:
$ sublime_text --project /repo/myprj/default.sublime-project
should just work. But it doesn't (see below).
Another approximation that seemed reasonable:
setting "hot_exit" and "remember_open_files" to false, and then invoking ST with:
$ sublime_text --data /repo/myprj --project default.sublime-project
But ST3 either doesn't find the project file (via --data), unless I chdir there first (--data seems to be no longer supported?), and it either doesn't auto-open any workspace files from last time (despite a previous "Project / Save Workspace As..."), or, if I set "remember_open_files" back to true, it just re-opens the last open files regardless of the project given on the command line.
I guess the issue is the workspace file not being handled automatically for some reason, and I'm just missing some trivial step somewhere. (The official docs (and also the unofficial) seem to discuss command-line switches for OS X only, and asking for --help didn't actually help with this one.)
(Please note: I wouldn't like to launch ST first, and then switch to some project from inside manually, and I also don't want to store the sublime-project/-workspace files outside of the prj. dir.) Thanks a lot!
I seached for a solution for a similar problem these days and didn't find a proper way. So i created an automator app with a small apple script. Maybe this helps you too.
Open Automator and Choose news Application.
Create an action to start Sublime Text 2
Insert an action to perfom the following apple script:
delay 0.2
tell application "System Events"
tell process "Sublime Text 2"
tell menu bar 1
tell menu bar item "Project"
tell menu "Project"
tell menu item "Recent Projects"
tell menu "Recent Projects"
click menu item "~/yourproject.sublime-project"
keystroke "p" using {command down, shift down}
end tell
end tell
end tell
end tell
end tell
end tell
end tell
For anyone still looking to do this, you can launch the built-in command line tool and launch it with a project like so (Mac OSX):
"/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" --project "absolute-path-to-your.sublime-project"

tmux status bar configuration

How is the status bar is customized? I noticed in this youtube video (at 3:05 - image below), the status bar looks very different than the default one that I see after installing tmux on my Mac OS X.
In particular, I like how the middle of the status bar shows the current program and the left side shows the name of only the current session. In comparison, my setup shows the name of all of the sessions and doesn't show the current application (for the currently focused pane).
If anyone could show me a sample configuration that could do this or show me where I can find the customization rules, that would be great! Thanks!
Update: In case anyone is curious, I was able to customize a status bar that is similar to the one seen in the video (minor tweaks) and you can find my config file on my github if you'd like to see an example.
The man page has very detailed descriptions of all of the various options (the status bar is highly configurable). Your best bet is to read through man tmux and pay particular attention to those options that begin with status-.
So, for example, status-bg red would set the background colour of the bar.
The three components of the bar, the left and right sections and the window-list in the middle, can all be configured to suit your preferences. status-left and status-right, in addition to having their own variables (like #S to list the session name) can also call custom scripts to display, for example, system information like load average or battery time.
The option to rename windows or panes based on what is currently running in them is automatic-rename. You can set, or disable it globally with:
setw -g automatic-rename [on | off]
The most straightforward way to become comfortable with building your own status bar is to start with a vanilla one and then add changes incrementally, reloading the config as you go.1
You might also want to have a look around on github or bitbucket for other people's conf files to provide some inspiration. You can see mine here2.
1 You can automate this by including this line in your .tmux.conf:
bind R source-file ~/.tmux.conf \; display-message "Config reloaded..."
You can then test your new functionality with Ctrlb,Shiftr. tmux will print a helpful error message—including a line number of the offending snippet—if you misconfigure an option.
2 Note: I call a different status bar depending on whether I am in X or the console - I find this quite useful.
I used tmux-powerline to fully pimp my tmux status bar. I was googling for a way to change to background of the status bar when your typing a tmux command. When I stumbled on this post I thought I should mention it for completeness.
Update: This project is in a maintenance mode and no future functionality is likely to be added. tmux-powerline, with all other powerline projects, is replaced by the new unifying powerline. However this project is still functional and can serve as a lightweight alternative for non-python users.
I have been playing about with tmux today, trying to customised a little here and there, managed to get battery info displaying on the status right with a ruby script.
Copy the ruby script from http://natedickson.com/blog/2013/04/30/battery-status-in-tmux/ and save it as:
battinfo.rb in ~/bin
To make it executable make sure to run:
chmod +x ~/bin/battinfo.rb
edit your ~/.tmux.config and include this line
set -g status-right "#[fg=colour155]#(pmset -g batt | ~/bin/battinfo.rb) | #[fg=colour45]%d %b %R"
Do C-b, :show which will show you all your current settings. /green, nnn will find you which properties have been set to green, the default. Do C-b, :set window-status-bg cyan and the bottom bar should change colour.
List available colours for tmux
You can tell more easily by the titles and the colours as they're actually set in your live session :show, than by searching through the man page, in my opinion. It is a very well-written man page when you have the time though.
If you don't like one of your changes and you can't remember how it was originally set, you can open do a new tmux session. To change settings for good edit ~/.tmux.conf with a line like set window-status-bg -g cyan. Here's mine: https://gist.github.com/9083598

How do I get a file off google-api-java-client?

OK i want download the the following open source code: http://code.google.com/p/google-api-java-client/source/browse/calendar-v2-atom-android-sample/?repo=samples
I am lead to believe you need to use mercurial for this but have yet to find a tutorial on how. Why is there not a download zip file type thing for this?
I am using eclipse.
How do I get this example?
You can get each file individually by clicking it then right-click "View raw file" in the right column and choose "Save" (which may say something slightly different depending on your browser.)
I don't know about this project, but usually you can download the samples in the zips on the downloads tab
If you want to do it faster than that, you can find a Mercurial client for most operating systems at https://www.mercurial-scm.org/downloads.
Once you have Mercurial installed, running the command
hg clone https://code.google.com/p/google-api-java-client.samples/ google-api-java-client-samples
will give you a full copy of the current version in the current directory.