Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a promise object in R?

Tags:

r

Can anyone give me an explanation of a promise object in R? I'm still new to R. So thanks in advance for keeping it simple (if possible).

I couldn't find a brief description nor in literature neither at web.

like image 924
user7364919 Avatar asked Jan 02 '17 11:01

user7364919


People also ask

What is object Promise?

The Promise object represents the eventual completion (or failure) of an asynchronous operation and its resulting value. To learn about the way promises work and how you can use them, we advise you to read Using promises first.

What is Promise in Rstudio?

A promise is a placeholder object for the eventual result (or error) of an asynchronous operation. This function is not generally needed to carry out asynchronous programming tasks; instead, it is intended to be used mostly by package authors who want to write asynchronous functions that return promises.

Why am I getting a Promise object?

You are getting [object Promise] as value because you are calling an asynchronous function inside a synchronous code. This means the synchronous code runs line by line giving no room for asynchronous code to wait and give a response (the promise).

Is a Promise an object or a function?

A Promise is an object representing the eventual completion or failure of an asynchronous operation. Since most people are consumers of already-created promises, this guide will explain consumption of returned promises before explaining how to create them.


1 Answers

Promise objects are used within packages to make objects available to users without loading them into the memory. Unfortunately, it is not possible to determine if an object is a promise object, nor it is possible to figure out the environment in which it was created. For example : You can create a promise object to delay evaluation of a variable until it is (first) needed. You can do it using delayedAssign function.

 x <- 1
 y <- 2
 z <- 3
 delayedAssign("v", c(x, y, z))
 x <- 5
 v
#[1] 5 2 3

Reference : http://130.132.212.207/mediawiki/images/0/09/R_in_a_Nutshell.pdf

like image 72
Sachin Vardhan Avatar answered Oct 12 '22 11:10

Sachin Vardhan