Сделать R Script возвращать статус во внешнюю программу [duplicate]

Простой рекурсивный чек будет достаточно и будет возвращаться как можно раньше, мы предполагаем, что он не является списком или содержит не-списки, он не пуст

  def isEmpty (alist)  : try: for a in alist: if not isEmpty (a): return False, за исключением: # мы будем здесь, если alist не является возвратом итератора / списка False return True alist = [] blist = [alist] # [[]]  clist = [alist, alist, alist] # [[], [], []] dlist = [blist] # [[[]]] elist = [1, isEmpty, dlist] if isEmpty (alist): print "alist  «is empty» if isEmpty (dlist): print «dlist is empty», если не isEmpty (elist): print «elist is not empty»  

Вы можете дополнительно улучшить его, чтобы проверить рекурсивный список или нет объектов списка, или может быть пустым dicts и т. д.

52
задан Iterator 7 October 2011 в 14:19
поделиться

2 ответа

Это аргумент quit(). См. ?quit.

Аргументы :

status: the (numerical) error status to be returned to the operating
        system, where relevant.  Conventionally ‘0’ indicates
        successful completion.

Подробности :

 Some error statuses are used by R itself.  The default error
 handler for non-interactive use effectively calls ‘q("no", 1,
 FALSE)’ and returns error code 1.  Error status 2 is used for R
 ‘suicide’, that is a catastrophic failure, and other small numbers
 are used by specific ports for initialization failures.  It is
 recommended that users choose statuses of 10 or more.
54
ответ дан Joshua Ulrich 16 August 2018 в 14:30
поделиться
quit(status=1)

Заменить 1 любым кодом выхода, который вам нужен.

3
ответ дан Stephen Rauch 16 August 2018 в 14:30
поделиться
Другие вопросы по тегам:

Похожие вопросы: