Troubleshooting/ common programming errors

`pandoc-citeproc` error

After updating my MacOS to Ventura, I was unable to knit documents. I ran into the following error:

[WARNING] Deprecated: pandoc-citeproc filter. Use --citeproc instead.
Error running filter pandoc-citeproc:
Could not find executable pandoc-citeproc
Error: pandoc document conversion failed with error 83
In addition: Warning message:
Can't find generic `sew` in package knitr to register S3 method.
ℹ This message is only shown to developers using devtools.
ℹ Do you need to update knitr to the latest version? 
Execution halted

Solution

This error was fixed by running: remotes::install_github("crsh/rmdfiltr")

Scripts tha need internet suddenly take forever on VPN

One possibility is that the program tries to use IPv6 but Duke's VPN isn't allowing it.

The instructions are for Wi-Fi connections on MacOS computers. If that's not your case, you can do the first check and then ask Zhenya for instructions for your case.

To check that it is the same problem

Open this and this links in the browser. The first one might require you to confirm that you trust that website. If either of these doesn't open at all then this solution won't help you, sorry. If they do open, start python/iPython in the terminal and issue the following commands one by one:

import requests
requests.get('http://www.testingmcafeesites.com/')
requests.get('https://www.google.com/')

If the first one quickly outputs "<Response [200]>" but the second one hangs then this is probably the same problem.

To check if the problem has the same source

In the shell, run

networksetup -getinfo "Wi-Fi" | grep IPv6:

If it outputs IPv6: Automatic then the problem might have the same source.

To solve

Do this only if both checks above pass.

networksetup -setv6off "Wi-Fi"

Set a reminder to undo this change at some later point with

networksetup -setv6automatic "Wi-Fi"
[email protected]. Permission denied (publickey)

Example:

git@github.com: Permission denied (publickey). 
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Error in strsplit(command, "\\s+")[[1]] : subscript out of bounds
In addition: Warning messages:
1: In system2(git_bin, arguments, wait = TRUE, stdout = TRUE) :
  Running command ''/usr/bin/git' -C /Users/xx123/BLAB_DATA/cdi_spreadsheet fetch --tags --prune' had status
2: In get_df_file("cdi_spreadsheet". "cdi.feather". version = version) :

Why? You have a repository cloned from GitHub via ssh and your ssh key is no longer recognized by GitHub. Why is it no longer recognized? I don't know.

To solve

  • Look around the error message to figure out what repository is causing the problem. In the example above, it was cdi_spreadsheet.

  • Find GitHub https URL of the repo (O and the path to the BLAB_DATA folder. For cdi_spreadsheet, these are ~/BLAB_DATA/cdi_spreadsheet and https://github.com/BergelsonLab/cdi_spreadsheet.git.

  • In Terminal,

cd ~/BLAB_DATA/cdi_spreadsheet
git remote set-url origin https://github.com/BergelsonLab/cdi_spreadsheet.git
git fetch  # to check the connection
An error about gfortran when installing R packages or running renv::restore()

Follow these instructions:New computer setup

After downloading gfortran following instructions on https://mac.r-project.org/tools/, if R fails to locate it, go to the file${R_HOME}/etc/Makeconf and update the following lines to update the location of gfortran:

FC = /opt/gfortran/bin/gfortran -mtune=native
FLIBS =  -L/opt/gfortran/lib/gcc/aarch64-apple-darwin20.0/12.2.0 -L/opt/gfortran/lib -lgfortran -lemutls_w -lquadmath
Error installing package (e.g., xml2) due to unable to load shared object ...

Go to the bottom of the error message, which likely includes a line like:

Reason: tried: '/Library/Frameworks/R.framework/Resources/lib/libicuuc.73.1.dylib' (no such file), '/Library/Java/JavaVirtualMachines/jdk-17.0.1+12/Contents/Home/lib/server/libicuuc.73.1.dylib' (no such file)

This means R failed to locate a specific file required for installing the package (in the example above, libicuuc.73.1.dylib. Try searching for this file in Finder and it might show up in another folder. If that happens, create a symlink that points from the existing file to where R was looking for, e.g.,

ln -s {where the file locates} {where R wants to find the file}
ln -s /Users/lilyzihuizhu/miniconda3/lib/libicuuc.73.1.dylib /Library/Frameworks/R.framework/Resources/lib/libicuuc.73.dylib
Rstudio freezes after opening a file/R project

Try deleting the .Rproj.user/ folder and reopening the R project. This folder will regenerate automatically.

Line xxx Execution halted under the Render tab in Rstudio

This error is most often caused by a piece of inline (e.g., We had `r N` p articipants). To troubleshoot:

  • Within the "Render" tab, in addition to the "Output" sub-tab, there should be an "Issues" sub-tab. Click on it, find out which variable caused the issue, and then look for the corresponding code in the document.

  • If the error message doesn't let you find the specific piece of inline code easily, you can use a custom evaluate.inline knitr knitting hook for inline code that will process the error and let the knitting continue. You should see an error message and a warning directly under the "Render" tab and in place of the intended output in the rendered document. Add the code below to the setup chunk. Delete after fixing the error to avoid accidentally missing future errors like this.

knitr::knit_hooks$set(
  # based on https://stackoverflow.com/a/62041765/3042770
  evaluate.inline = function(code, envir = knit_global()) {
    # Evaluate the code with visibility tracking
    result <- tryCatch(
      # Line copied from knitr::knit_hooks$get('evaluate.inline')
      withVisible(eval(xfun::parse_only(code), envir = envir)),
      error = function(e) {
        list(value = sprintf("`<<<` ERROR in: `%s`: %s `>>>`", code, e$message), is_error = TRUE)
      }
    )
    
    if (!is.null(result$is_error) && result$is_error) {
      # Print a message and a warning to the console
      cat(result$value)
      warning(result$value)
      # Return the message so we can see it in the rendered document
      knitr::asis_output(result$value)
    } else {
      # Branch copied from knitr::knit_hooks$get('evaluate.inline')
      if (result$visible) 
        knitr::knit_print(result$value, inline = TRUE, options = knitr::opts_chunk$get())
    }
  }
)
xcrun error

If you get

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

Try one of (solutions found here):

xcode-select --install
sudo xcode-select --install
sudo xcode-select --reset

fatal error: 'stdlib.h' file not found

If you get

installing the source package 'htmltools'
trying URL 'https://cran.rstudio.com/src/contrib/htmltools_0.5.4.tar.gz'
Content type 'application/x-gzip' length 131047 bytes (127 KB)
==================================================
downloaded 127 KB
* installing *source* package 'htmltools' ...
** package 'htmltools' successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/usr/local/include   -fPIC  -Wall -g -O2  -c init.c -o init.o
In file included from init.c:1:
/Library/Frameworks/R.framework/Resources/include/R.h:55:11: fatal error: 'stdlib.h' file not found
# include <stdlib.h> /* Not used by R itself, but widely assumed in packages */
          ^~~~~~~~~~
1 error generated.
make: *** [/Library/Frameworks/R.framework/Resources/etc/Makeconf:167: init.o] Error 1
ERROR: compilation failed for package 'htmltools'
* removing '/Library/Frameworks/R.framework/Versions/4.0/Resources/library/htmltools'
* restoring previous '/Library/Frameworks/R.framework/Versions/4.0/Resources/library/htmltools'
Warning in install.packages :
  installation of package 'htmltools' had non-zero exit status
The downloaded source packages are in
	'/private/var/folders/xm/jlfby6mj5bjblsv4s8j4vb1xpk6dsg/T/RtmpXRJejQ/downloaded_packages'

Check your PATH environment variable with Sys.getenv('PATH') or with echo $PATH in the terminal. If miniconda/anaconda are the first ones listed, try rearranging the paths so that /usr/local/bin is the first path in the list. Make sure to use : as the separator between paths.

Temporarily, use Sys.setenv(PATH = '???') in R or export PATH=??? (no spaces around =) in the terminal. A long-term solution is to manipulate PATH at the system level.

Here is an example of setting PATH in the terminal:

$ echo $PATH
/Users/ek221/miniconda3-arm64/condabin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/cisco/anyconnect/bin
$ export PATH=/usr/local/bin:/Users/ek221/miniconda3-arm64/condabin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/cisco/anyconnect/bin

No longer relevant but might need them anyway

An email about CrowdStrike from Duke IT

Problem: you got an email that contains something like this:

We are writing to ask you for assistance in securing a Duke-owned device that does not appear to have the CrowdStrike Falcon agent installed as required by Duke's cybersecurity policy (https://security.duke.edu/policies/security-requirements-duke-owned-computers):

Solution: someone with admin right on the computer should follow the instructions here:

https://oit.duke.edu/help/articles/kb0035361

Last updated