Java (jdk) called by package differs from current system version

Problem: Trying to call library(“xlsx”) throws error message indicating that JDK path cannot be found, but you have Java already installed. Your version is more recent than what the package is expecting. You attempt to update your system/IDE so that calls for JDK now point to the newer version

$ sudo R CMD javareconf

— but you get the following error message

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

Issue: (1) Many IDEs and programming language packages rely on differing developer versions than might be installed on your OS. For example,  if you upgraded your Java from 9 to 10, and an R-package (such as ‘rJava’ or ‘XLSX’) was built so as to specifically call on directories with the name “/Library/Java/JavaVirtualMachines/jdk-9.jdk/”. (2) You must have:

  1. install_name_tool
  2. This requires Command Line Tools for Xcode installed/downloaded from Apple

Solution:

  • Ensure you have Java (jdk) installed.

$ java -version

$ sudo R CMD javareconf

  •  QUIT & RESTART RStudio

 

Advertisement

Unix – replace |pipe| with tab in MacOS Terminal

Problem:

  • MacOS Terminal does not allow use of \t for “tab” delimiter
  • Source file may have one or more separators set as non-tab characters
    • comma ,
    • pipe |
    • etc
  • Functions to read data cannot read/import data if source has multiple different delimiter characters

Solution:

  • Convert source file using sed in terminal (unix) window:
  • Enter tab — <control> v <tab>

sed ‘s/       /|/g’ source_file > destination_file

Rstudio lost connection to git

Problem: Git was installed, and after update of MacOS, Rstudio no longer can locate git binary executable. When in Rstudio, the git tab is missing.

Testing:

  1. run git from command line — should not throw error.
  2. run —–> which git

Solution: Make sure you have latest version of xcode installed.

xcode-select –install

Reference: https://apple.stackexchange.com/questions/254380/macos-sierra-invalid-active-developer-path

Thank you cuadraman

 

Merging 2 datasets by a common variable (different name)

When doing outer join (match merge) in SAS by a common variable, and this variable has a different name in each dataset, you must rename the common variable. This can done within one (single) data step:

DATA TTTEMP;

Merge librarynam.dataset1 ( Rename= (common_varOLD1= common_varNEW ) ) librarynam.dataset2 (Rename= (common_varOLD2= common_varNEW) ) ;

BY common_varNEW;

RUN;

How to generate p-values for a covariate with linear and quadratic term in PROC Logistic

Step 1: Capture variables from Proc Logistic

PROC Logistic data= <dataset> ;

Class
<Var-1>  <var-2>  <categorical_var-n>; ** can go here with “/“ e.g. param=glm ;

Model
<Outcome_Var> = <Main-predictor> <Factor-1> <Factor-n> <Non-linear_Covariate> | <Non-linear_Covariate> ;

Oddsratio <Non-linear_Covariate> / at (MSPSS_scale= 20 30 40 50 60 70 80 90 ); ;

ODS Output OddsRatios = OR_Dataset ;
ODS Output OddsRatiosWald = OR_Wald_Dataset ;

RUN;

Step 2: Generate variables for p-values for linear factors

DATA orwp_linear;

Set OR_Dataset;

alpha=.05 ;
stderr=abs(log(uppercl)-log(lowercl)) / (2*probit(1-alpha/2)) ;
wald=(log(oddsratioest)/stderr)**2 ;
p=1-probchi(wald,

Drop alpha ;

RUN;

Step 3: Generate variables for p-values for non-linear factors

 

DATA orwp_nonlinear;

Set OR_Wald_Dataset;

alpha=.05 ;
stderr=abs(log(uppercl)-log(lowercl)) / (2*probit(1-alpha/2)) ;
wald=(log(oddsratioest)/stderr)**2 ;
p=1-probchi(wald,

Drop alpha ;

RUN;

Step 4: Print table of linear and non-linear factors

 

PROC Print data= orwp_linear label noobs;

Format p pvalue6. ;
Label stderr=”Standard Error” wald=”Wald Chi-Square” p=”Pr > ChiSq”;

RUN;

PROC Print data= orwp_nonlinear label noobs;

Format p pvalue6. ;
Label stderr=”Standard Error” wald=”Wald Chi-Square” p=”Pr > ChiSq”;

RUN;