{"id":23051518,"url":"https://github.com/averissimo/notes-on-r","last_synced_at":"2026-01-31T10:02:12.192Z","repository":{"id":147521824,"uuid":"76380097","full_name":"averissimo/notes-on-r","owner":"averissimo","description":"General notes and tips on R","archived":false,"fork":false,"pushed_at":"2016-12-13T21:18:11.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-08T11:48:25.662Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/averissimo.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-12-13T16:59:39.000Z","updated_at":"2016-12-13T16:59:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"6d1e7158-acc5-454d-ae33-5e1a7941c6d3","html_url":"https://github.com/averissimo/notes-on-r","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/averissimo/notes-on-r","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/averissimo%2Fnotes-on-r","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/averissimo%2Fnotes-on-r/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/averissimo%2Fnotes-on-r/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/averissimo%2Fnotes-on-r/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/averissimo","download_url":"https://codeload.github.com/averissimo/notes-on-r/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/averissimo%2Fnotes-on-r/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28937809,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-31T08:53:31.997Z","status":"ssl_error","status_checked_at":"2026-01-31T08:51:38.521Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-15T23:46:14.835Z","updated_at":"2026-01-31T10:02:12.186Z","avatar_url":"https://github.com/averissimo.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"---\ntitle: \"Notes on R\"\nauthor: \"André Veríssimo\"\noutput: github_document\n---\n\n```{r setup, include=FALSE}\nknitr::opts_chunk$set(echo = TRUE)\n```\n\n## Benchmarking parallel methods with `cor`\n\n### Functions to build dataset\n\n```{r fun_aux}\nlibrary(futile.logger)\n\ngenData \u003c- function(reps = 100, sample.size = 1000) {\n  genDataAux \u003c- function(template = runif(1000), correlation = 1) {\n    xdata \u003c- array(0, length(template))\n    correlated.ixs \u003c- template \u003c correlation\n    xdata[correlated.ixs] \u003c- template[correlated.ixs] + .0005 * runif(length(template[correlated.ixs]))\n    xdata[!correlated.ixs] \u003c- template[!correlated.ixs] + .05 * rnorm(length(template[!correlated.ixs]))\n    return(xdata)\n  }\n  \n  template \u003c- runif(sample.size)\n  dat \u003c- sapply(seq(reps), function(e) {genDataAux(template , correlation = abs(.3 + runif(1))) })\n  #\n  flog.info('Size of generated data:', dim(dat), capture = T)\n  return(list(dat = dat, template = template)) \n}\n\nmy.fun \u003c- function(dat.ix) {\n  cor(dat$template, dat$dat[,1], method = 'pearson')\n}\n```\n\n### Setting up common benchmark parameters\n\n```{r setup_params}\nlibrary(microbenchmark)\n\nntimes \u003c- 10\n#\ndat \u003c- genData(reps = 1, sample.size = 1000)\n#\nreps \u003c- 100000;\n\nflog.info('')\nflog.info('')\nflog.info('Repeating benchmarks %d times to find statistics', ntimes)\nflog.info('  -\u003e %d samples per variables', length(dat$template))\nflog.info('  -\u003e %d correlations being calculated', reps)\nflog.info('')\n\n```\n\n### Benchmark Xapply functions\n\n```{r xapply}\nmicrobenchmark(\n    lapply(1:reps, my.fun)\n  , sapply(1:reps, my.fun)\n  , vapply(1:reps, my.fun, array(double(0), 1))\n  , times = ntimes)\n\n```\n\n### Benchmark different combinations of mcapply\n\n```{r mclapply}\nlibrary(parallel)\nmicrobenchmark(\n    mclapply(1:reps, my.fun, mc.cores = 16)\n  , mclapply(1:reps, my.fun, mc.cores = 15)\n  , mclapply(1:reps, my.fun, mc.cores = 14)\n  , times = ntimes)\n```\n\n### Benchamark different combinations of foreach\n\n```{r foreach}\nlibrary(parallel)\nlibrary(foreach)\nlibrary(doMC) # parallel computing\nregisterDoMC(cores = 16) \nflog.info('16 cores')\nmicrobenchmark(\n    foreach(el = 1:reps) %dopar% { my.fun(el) }\n  , foreach(el = 1:reps, .inorder = F ) %dopar% { my.fun(el) }\n  , foreach(el = 1:reps, .combine = 'c') %dopar% { my.fun(el) }\n  , foreach(el = 1:reps, .combine = 'c', .inorder = F ) %dopar% { my.fun(el) }\n  , foreach(el = 1:reps, .combine = 'cbind') %dopar% { my.fun(el) }\n  , foreach(el = 1:reps, .combine = 'cbind', .inorder = F ) %dopar% { my.fun(el) }\n  , times = ntimes)\n```\n\n\n### Benchmark combinations of BiocParallel  \n\n```{r bioc_parallel}\nlibrary(BiocParallel)\n#\nmicrobenchmark(\n    bplapply(1:reps, my.fun, BPPARAM = MulticoreParam(16))\n  , bplapply(1:reps, my.fun, BPPARAM = MulticoreParam(15))\n  , bplapply(1:reps, my.fun, BPPARAM = MulticoreParam(14))\n  , times = ntimes)\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faverissimo%2Fnotes-on-r","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faverissimo%2Fnotes-on-r","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faverissimo%2Fnotes-on-r/lists"}