Skip to content

Instantly share code, notes, and snippets.

@dcomtois
dcomtois / r_c.txt
Last active January 10, 2024 19:08
Linking R internal & primitive C functions with appropriate source files. --- printname = R function name ; c.entry = C function ; sourcefile = relevant C source file; line_no: line featuring fn definition (not all checked)
printname c.entry file line_no
- do_arith R-4.0.3\src\main\arithmetic.c 411
! do_logic R-4.0.3\src\main\logic.c 40
!= do_relop R-4.0.3\src\main\relop.c 51
$ do_subset3 R-4.0.3\src\main\subset.c 1206
$<- do_subassign3 R-4.0.3\src\main\subassign.c 2081
%% do_arith R-4.0.3\src\main\arithmetic.c 411
%*% do_matprod R-4.0.3\src\main\array.c 1228
%/% do_arith R-4.0.3\src\main\arithmetic.c 411
& do_logic R-4.0.3\src\main\logic.c 40
@tleonardi
tleonardi / tanimoto.R
Created February 23, 2015 11:52
Tanimoto distance in R
tanimoto <- function(x, similarity=F) {
res<-sapply(x, function(x1){
sapply(x, function(x2) {i=length(which(x1 & x2)) / length(which(x1 | x2)); ifelse(is.na(i), 0, i)})
})
if(similarity==T) return(res)
else return(1-res)
}
x <- data.frame(Samp1=c(0,0,0,1,1,1,0,0,1), Samp2=c(1,1,1,1,1,1,0,0,1), Samp3=c(1,0,0,1,0,0,0,0,0), Samp4=c(1,1,1,1,1,1,1,1,1))
tanimoto(x)
@yamaguchiyuto
yamaguchiyuto / basic_plot.py
Last active March 7, 2022 15:51
Plot degree distribution (Freq, CDF, CCDF) from edgelist data
import sys
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt
def plot(data,filename,degreetype):
""" Plot Distribution """
plt.plot(range(len(data)),data,'bo')
plt.yscale('log')
plt.xscale('log')
## Empty list -- just use the empty environment for this.
nil <- function() {
emptyenv()
}
## Test if a list is the empty list:
is_empty <- function(lis) {
identical(lis, nil())
}
These code snippets have been tested on R 3.1.0 and Mac OS 10.9.3. They presumably do *not* work on R 2.X!
## Enter these commands in the Mac OS Terminal
# use faster vecLib library
cd /Library/Frameworks/R.framework/Resources/lib
ln -sf /System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Versions/Current/libBLAS.dylib libRblas.dylib
# return to default settings
cd /Library/Frameworks/R.framework/Resources/lib
@trestletech
trestletech / server.R
Last active May 25, 2017 21:30
An example of doing prolonged, iterative computation in Shiny.
library(shiny)
shinyServer(function(input, output, session) {
# The number of iterations to perform
maxIter <- 50
# Track the start and elapsed time
startTime <- Sys.time()
output$elapsed <- renderText({
@rsobik
rsobik / boost.sh
Created November 17, 2013 13:20
Build Boost 1.55.0 for iOS 7 and OS X including 64 Bit
#===============================================================================
# Filename: boost.sh
# Author: Pete Goodliffe
# Copyright: (c) Copyright 2009 Pete Goodliffe
# Licence: Please feel free to use this, with attribution
# Modified version
#===============================================================================
#
# Builds a Boost framework for the iPhone.
# Creates a set of universal libraries that can be used on an iPhone and in the
@gizmaa
gizmaa / Plot_Examples.md
Last active May 15, 2025 02:57
Various Julia plotting examples using PyPlot
@romainfrancois
romainfrancois / gist:7117691
Last active April 12, 2020 17:22
create list with more than 20 elements (different syntax)
#include <Rcpp.h>
using namespace Rcpp ;
template <typename T>
inline void set_item_impl( List& target, int i, const T& obj, CharacterVector& names, traits::true_type ){
target[i] = obj.object ;
names[i] = obj.name ;
}
template <typename T>
@romainfrancois
romainfrancois / biglist.cpp
Created October 23, 2013 12:15
create lists with more than 20 elements
#include <Rcpp.h>
using namespace Rcpp ;
template <typename T>
inline void set_item_impl( List& target, int i, const T& obj, CharacterVector& names, traits::true_type ){
target[i] = obj.object ;
names[i] = obj.name ;
}
template <typename T>