Posts Tagged git

Build R package from GNU Emacs on Windows 10

I use Windows 10 machine, at work, with GNU Emacs installed from choco repository. Script from my article Run shiny R application from Emacs was not working like in my old Windows 7. First thing is that it was not founding my R binary and I’ve got error:

apply: Spawning child process: Invalid argument

First thing was adding path to R binary second issue was path to Root of the package

Here is first function based on the one from previous article:

(defun call-r-command (command-list)
  "run R command in shell buffer window

  if there is displayed buffer that have shell it will use that window"
  (let* ((name "*R*")
         (new-buffer (get-buffer-create name))
         (old-buff (get-buffer name))
         ;; run R command
         (script-proc-buffer
          (apply 'make-comint-in-buffer
                 "script"
                 new-buffer
                 "c:/Program Files/R/R-3.5.2/bin/R.exe"
                 nil
                 command-list))
         ;; if there is *R* buffer try to find its window
         (old-window (if old-buff (get-buffer-window old-buff)))
         ;; use old window or find any that have shell mode
         (window (or old-window
                     (get-window-with-mode '(comint-mode eshell-mode))))
       (script-proc (get-buffer-process script-proc-buffer)))
    ;; reuse window or create new one
    (if window
        (set-window-buffer window new-buffer)
      (switch-to-buffer-other-window new-buffer))))

This function execute R command, so my new shiny function is shorter

(defun shiny ()
  "run shiny R application in shell buffer"
  (interactive)
  (let ((R (concat "shiny::runApp('" default-directory "')")))
    (call-r-command `("-e" ,R "--no-save"))))

Next is function that return root of git repo (since my R package is also git repo):

(defun shell-line (command)
  "Function execute shell command and return the result as single line"
  (replace-regexp-in-string "\n" "" (shell-command-to-string command)))

The problem with git on Windows 10 in GNU Emacs (or because of shell-command-to-string function) is that path is in Unix format not in Windows format, so I need to fix the path to use it in my R calling script.

(defun git-root-repo ()
  "Function return root of the git repo"
  (interactive)
  (replace-regexp-in-string "/mnt/c/" "c:/" (shell-line "git rev-parse --show-toplevel")))

Now my final function that build the R package:

(defun build-r-package ()
  "Build R package using git root directory as path to R package"
  (interactive)
  (call-r-command `("CMD" "INSTALL" ,(git-root-repo))))

Missing function for finding buffer with same major mode can be found in my previous article Run shiny R application from Emacs.

, ,

Leave a comment

How to refresh the coverage badge in github README after coverage change

In my project jQuery Terminal I commited a change that make coverage was changed from 79% to 80% (the project is using jasmine, travis and coveralls service) but my badge in README still was showing 79%, even after removing cache. I’ve fixed the issue by adding md5 hash (I know it have been broken, but we don’t use anything secure here) of the spec file after url of my badge, so each time I add something to spec file I’ve get different url, so github wont cache the file.

I’m using make as my build script and I have two README files. Source with .in extension and result with .md extension so I’ve put another variable (I’m already using BRANCH and VERSION in README):

https://coveralls.io/repos/github/jcubic/jquery.terminal/badge.svg?branch=BRANCH&CHECKSUM

and in my Makefile I’ve added:

SPEC_CHECKSUM=`md5sum spec/terminalSpec.js | cut -d' ' -f 1`

README.md: README.in .$(VERSION)
    $(SED) -e "s/{{VER}}/$(VERSION)/g" -e "s/{{BRANCH}}/$(BRANCH)/g" -e "s/{{CHECKSUM}}/$(SPEC_CHECKSUM)/" < README.in > README.md

This is simplification, actually I have more code, you can see in my Makefile

if you have more then one spec file you can use this to generate checksum

SPEC_CHECKSUM=`cat spec/*.js | md5sum | cut -d' ' -f 1`

This will also work if you have different language and different build system.

,

Leave a comment

%d bloggers like this: