Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

tiki19

macrumors newbie
Original poster
Aug 20, 2019
3
1
CH
Hi all

I'm a mac newbie and also not really experienced with using the terminal etc.
I'm using macOS Mojave version 10.14.5 and R 3.6.1

I'm trying to run a R script with the terminal. Unfortunately, the tutorial is only for Windows. In the beginning the tutorial says:
type the command SETX EWASTE_SCRIPT_PATH "[FOLDER SCRIPT PATH]" and enter the location of the folder with the scripts between the "". Right-click and choose paste, to paste this location that was copied to the clipboard before. The command would then look for instance like this: SETX EWASTE_SCRIPT_PATH "F:\Vincent\Documents\ewaste-master\scripts".

I tried to add the path in the .bash_profile by adding the following: export PATH=/path/to/location:$PATH, with /path/to/location referring to /ewaste-master/scripts

if I type in echo $PATH, i get:
/Users/estherthiebaud/Desktop/ewaste-master/scripts:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

After that, I run the R script. It starts running but then i get the following error:
file.exists(Sys.getenv("EWASTE_SCRIPT_PATH")) is not TRUE
Ausführung angehalten
##execution stopped in German

Then I also tryied to add in the .bash_profile
EWASTE_SCRIPT_PATH=/path/to/location:$EWASTE_SCRIPT_PATH
but that didn't help.

Now my question is: is there a way to still use this script with Mac with this Sys.getenv() or do I have to run it on Windows?

I also tried to run everthing directly in R, then I get the same error message, but with this addition:
Fehler: file.exists(Sys.getenv("EWASTE_SCRIPT_PATH")) ist nicht TRUE
objc[19492]: Class FIFinderSyncExtensionHost is implemented in both /System/Library/PrivateFrameworks/FinderKit.framework/Versions/A/FinderKit (0x7fffb02a23d8) and /System/Library/PrivateFrameworks/FileProvider.framework/OverrideBundles/FinderSyncCollaborationFileProviderOverride.bundle/Contents/MacOS/FinderSyncCollaborationFileProviderOverride (0x1093d7f50). One of the two will be used. Which one is undefined.

Thanks for your help!
 
I'm not an expert, but I think you need to quote your export statement i.e. export PATH="/path/to/location:$PATH"

I believe Bash will resolve your $PATH statement but only if it is quoted.

You should also be able to navigate ('cd') in the terminal to /ewaste-master/scripts and run your script there. Make sure the script is executable ('x' in directory permissions) and then type './{your script name}'. './' is shorthand for the current directory.
 
EWASTE_SCRIPT_PATH needs to be an actual path to a folder. The script errors out because the path doesn’t exist.

You can test by doing this in the terminal and replacing the path with a valid one before running the script:

Code:
export EWASTE_SCRIPT_PATH=/my/path/to/folder
 
Thank you very much for your help! @ neliason: yes, you are right, I think quotes are needed, but that still didn't resolve the problem.
@Krevnik: when I first type your code, then change the directory to /ewaste-master/scripts and run my script there, it starts running, but then more error messages occur (See below, unfortunately most of it in German). I assume it's also a problem, that all the path references in the script are written for windows with \ and not with /?

Lade nötiges Paket: getopt

Warnmeldung:

In normalizePath(file.path(SCRIPT_PATH, "..\\data\\tbl_Countries.csv")) :

path[1]="/Users/estherthiebaud/Desktop/ewaste-master/scripts/..\data\tbl_Countries.csv": No such file or directory

Fehler in file(file, "rt") : kann Verbindung nicht öffnen

Ruft auf: read.csv -> read.table -> file

Zusätzlich: Warnmeldung:

In file(file, "rt") :

kann Datei '/Users/estherthiebaud/Desktop/ewaste-master/scripts/..\data\tbl_Countries.csv' nicht öffnen: No such file or directory

Ausführung angehalten
 
seems like the writer went through the motions of making it cross-platform, but didn't actually test it on a unix machine.

by the way, you can set system enviromnment variables from within Rshell by

using Sys.setenv
Code:
Sys.setenv(EWASTE_SCRIPT_PATH="/Users/jeremy/Downloads/ewaste-master/scripts")
source("/Users/jeremy/Downloads/ewaste-master/scripts/main.R")
so far, I've edited line 46 of Main.R, installed half a dozen packages, and 03_POM_calculations.R is still bugging me about "package or namespace failed". Perhaps ticking the Install Dependencies box would have been a better idea. :sigh:

Code:
tbl_Countries <- normalizePath(file.path(SCRIPT_PATH, "../data/tbl_Countries.csv"))
 
  • Like
Reactions: Krevnik
here's the final output

Code:
> Sys.setenv(EWASTE_SCRIPT_PATH="/Users/jeremy/Downloads/ewaste-master/scripts")
> source("/Users/jeremy/Downloads/ewaste-master/scripts/main.R")
Loading required package: getopt
[1] "Looking for R scripts in '/Users/jeremy/Downloads/ewaste-master/scripts'"
[1] "Looking for data in '/Users/jeremy/Downloads/ewaste-master/data'"
[1] "... 2019-08-22 14:38:36: Sourcing script '01_Prodcom_confidentials.R'"
Loading required package: plyr
Loading required package: reshape2
[1] "... 2019-08-22 14:39:27: Sourcing script '02_Apparent_Consumption_Method.R'"
[1] "... 2019-08-22 14:39:46: Sourcing script '03_POM_calculations.R'"
Loading required package: dplyr

Attaching package: ‘dplyr’

The following objects are masked from ‘package:plyr’:

    arrange, count, desc, failwith, id, mutate, rename, summarise, summarize

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union

Loading required package: data.table
data.table 1.12.2 using 2 threads (see ?getDTthreads).  Latest news: r-datatable.com

Attaching package: ‘data.table’

The following objects are masked from ‘package:dplyr’:

    between, first, last

The following objects are masked from ‘package:reshape2’:

    dcast, melt

[1] "... 2019-08-22 14:40:08: Sourcing script '04_WEEE_calculations.R'"
[1] "... 2019-08-22 14:40:15: Sourcing script '05_Make_tblAnalysis.R'"
Loading required package: eurostat
trying URL 'https://ec.europa.eu/eurostat/estat-navtree-portlet-prod/BulkDownloadListing?sort=1&file=data%2Fenv_waselee.tsv.gz'
Content type 'application/octet-stream;charset=UTF-8' length 175615 bytes (171 KB)
==================================================
downloaded 171 KB

Table env_waselee cached at /var/folders/9j/0xq4k5c08xj98k0059b640bh0000gn/T//RtmpirnQIz/eurostat/env_waselee_date_code_FF.rds

I hope that's meaningful to you. I haven't used R in many many years.
 
Thank's for your help @jerwin and for bothering to find the script all by yourself (sorry for not posting the link or giving more background information)! I'm really grateful for that!
With your edit of Main.R it all runs now perfectly and I get the results (stored in the data folder of ewaste-master) I need!
 
  • Like
Reactions: jerwin
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.