Jan 5, 2016 - Making an Import Wheel in R

Comments

When we switch from a *nix development environment to a Windows one, or reverse the process, we have to be confront with the dependancies problem.

In that, despite of the previous wheel packrat existing, which is built by Rstudio, a robust tool for virtualizing the environment, I am glad to make another wheel, an import function, which inspired from Python.

This import function will load the dependancies, and install these uninstalled one. These will improve the environment problem.

import <- function(packages){
  for (i in 1:length(packages)){
    package = packages[i];
    char_package = package;
    # char_package <- as.character(substitute(char_package))
    loaded <- paste("package", char_package, sep = ":") %in% search() #

    # is it existing the package
    if(loaded){
      library(char_package,character.only = TRUE)
      cat(paste0("load  ",char_package," package"),"\n")
    }
    else{
      cat(paste0("can not find ",char_package,", we need to install it"),"\n");
      install.packages(package);
      library(char_package,character.only = TRUE)
    }
  }
}
# import dependencies

dependencies = c("RMySQL","ggplot2","httr")
import(dependencies)
## can not find RMySQL, we need to install it
## Warning: unable to access index for repository https://
## mran.revolutionanalytics.com/snapshot/2015-08-27/src/contrib
## Warning: package 'RMySQL' is not available (for R version 3.2.2)
## Loading required package: DBI
## Loading required package: methods
## can not find ggplot2, we need to install it 
## 
## The downloaded binary packages are in
## 	/var/folders/f2/9jwh0h8s4y70r1jl3s7cq_5c0000gn/T//Rtmpqbv9uE/downloaded_packages
## can not find httr, we need to install it 
## 
## The downloaded binary packages are in
## 	/var/folders/f2/9jwh0h8s4y70r1jl3s7cq_5c0000gn/T//Rtmpqbv9uE/downloaded_packages

Jan 3, 2016 - Using R and Google Sheets

Using R and Google Sheets

Today, I meet a big problem about my ERP system built in Google Sheets, and I don’t want to shape a too complicated one such as WordPress or Django.

In that, inspired by gspread, a python package, I am trying googlesheets package, a counterpart of another R package.

Firstly, download the git repository and install.

library(devtools)
devtools::install_github("hadley/readr")
## Downloading GitHub repo hadley/readr@master
## Error in curl::curl_fetch_memory(url, handle = handle): Timeout was reached
devtools::install_github("jennybc/googlesheets")
## Downloading GitHub repo jennybc/googlesheets@master
## Installing googlesheets
## Skipping 5 packages ahead of CRAN: dplyr, jsonlite, mime, Rcpp, tidyr
## '/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file  \
##   --no-environ --no-save --no-restore CMD INSTALL  \
##   '/private/var/folders/f2/9jwh0h8s4y70r1jl3s7cq_5c0000gn/T/RtmpN3HfZO/devtoolsc3c37718540a/jennybc-googlesheets-067e4a3'  \
##   --library='/Library/Frameworks/R.framework/Versions/3.2/Resources/library'  \
##   --install-tests

If you’re network blocked, you could download manually.

$git clone $git@github.com:jennybc/googlesheets.git
$R CMD INSTALL googlesheets

Now, we could manipulate googlesheets with R.

library(googlesheets)
gs_ls()                           # authenticated in a popup website
## Error: oauth_listener() needs an interactive environment.
ss <- gs_title("My_December_Table") # read a SpreadSheet from your accout
## Error: oauth_listener() needs an interactive environment.
gs_read(bb,ws=3,range="A1:D20")    # read a sheet, ws means WorkSheet number
## Error in inherits(ss, "googlesheet"): object 'bb' not found
bb <- gs_edit_cells(ss, input = head(iris), trim = TRUE) # edit the table
## Error in inherits(ss, "googlesheet"): object 'ss' not found
gs_read(ss)
## Error in inherits(ss, "googlesheet"): object 'ss' not found

the more method you can see the official manual and shiny exampl!

Reference:Jennifer in UsingR Conference 2015

Related Shiny Examples