This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>OpenCPU demo app</title> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> | |
<!-- ocpu library --> | |
<script src="//code.jquery.com/jquery-1.10.2.min.js"> </script> | |
<script src="//public.opencpu.org/js/opencpu-0.4.js"> </script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Assume httr 0.4 | |
library(httr) | |
stopifnot(packageVersion("httr") >= "0.4") | |
#submit a package to CRAN, step 1 | |
submit <- function(name, email, pkg, comment = "Thank you", popup = TRUE){ | |
stopifnot(file.exists(pkg)) | |
req1 = httr::POST ( | |
url = "http://xmpalantir.wu.ac.at/cransubmit/index2.php", | |
encode = "multipart", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The data stream is not JSON itself. It contains lines with JSON data. Therefore | |
# this example manually collapses it into a JSON array. The file is also quite | |
# large, so we would need to do some batch processing by splitting the file before | |
# feeding it to R. This example shows how to read first 20 records. | |
library(jsonlite) | |
gzdata <- gzcon(url("http://78.46.48.103/sample/hourly_14.json.gz")) | |
records <- readLines(gzdata, n = 20) | |
close(gzdata) | |
json <- paste0("[", paste0(records, collapse=","), "]") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Version 1 | |
deparse_vector1 <- function(x) { | |
stopifnot(is.character(x)) | |
vapply(x, deparse, character(1), USE.NAMES=FALSE) | |
} | |
# Version 2 | |
deparse_vector2 <- function(x) { | |
stopifnot(is.character(x)) | |
if(!length(x)) return(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' @useDynLib nameOfPackage C_escape_chars | |
deparse_vector3 <- function(x) { | |
.Call(C_escape_chars, x) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This http data stream contains lines of minified JSON data. Therefore | |
# we can batch process this line by line. To speed things up, we actually | |
# process 100 lines at a time, by collapsing them into a JSON array. | |
library(jsonlite) | |
stopifnot(packageVersion("jsonlite") >= "0.9.11") | |
# note that open="r" results in line-by-line reading. | |
gzstream <- gzcon(url("http://78.46.48.103/sample/hourly_14.json.gz", open="r")) | |
batches <- list(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Synchronous implementation of curl() connection | |
curl <- function(url){ | |
con <- rawConnection(raw(0), "r+"); | |
cat("Downloading ") | |
req <- httr::GET(url, httr::write_stream(function(x){ | |
cat(".") | |
writeBin(x, con) | |
})) | |
httr::stop_for_status(req) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# UTF8 tests on Windows | |
# Using R 3.1.2 for win64 with LC_CTYPE=English_United States.1252 | |
library(Rcpp) | |
# Part 1: simply echo a string | |
echo1src <- "#include <Rcpp.h> | |
// [[Rcpp::export]] | |
std::string echo1(std::string src){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Execute this script line by line in your favorite IDE | |
# It does not work via source() | |
library(V8) | |
data(diamonds, package="ggplot2") | |
# Create session | |
ct <- new_context() | |
ct$source("http://cdnjs.cloudflare.com/ajax/libs/crossfilter/1.3.11/crossfilter.min.js") | |
ct$assign("diamonds", diamonds) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> install.packages("RJSONIO") | |
Installing package into '/export/home/jeroen/R/i386-pc-solaris2.11-library/3.2' | |
(as 'lib' is unspecified) | |
--- Please select a CRAN mirror for use in this session --- | |
trying URL 'http://cran.rstudio.com/src/contrib/RJSONIO_1.3-0.tar.gz' | |
Content type 'application/x-gzip' length 1148375 bytes (1.1 MB) | |
opened URL | |
================================================== | |
downloaded 1.1 MB |
OlderNewer