Question: I have a requirement where I need to encrypt file of size 1-2 GB in azure function. In am using PGP core library to encrypt file in memory. The below code is throwing out of memory exception if file size is above 700 MB. Note:- I am using azure function. Scaling up of App service plan didn't help.

I there any alternate of Memory stream that I can use. After encryption , I am uploading file into blob storage.

```
var privateKeyEncoded = Encoding.UTF8.GetString(Convert.FromBase64String(_options.PGPKeys.PublicKey));
using Stream privateKeyStream = StringToStreamUtility.GenerateStreamFromString(privateKeyEncoded);
privateKeyStream.Position = 0;

var encryptionKeys = new EncryptionKeys(privateKeyStream);
var pgp = new PGP(encryptionKeys);

//encrypt stream
var encryptStream = new MemoryStream();

await pgp.EncryptStreamAsync(streamToEncrypt, encryptStream );

```

Answer: 
The problem with the code in the question is that comparing to "NA" is not the same as checking if the value is NA. What that is doing is comparing the value to a character string which contains N and A. Also note that comparing to NA always gives NA so we can't use that either. Instead use `is.na`.

```
my_df$b2 == "NA"
## [1]    NA FALSE FALSE FALSE    NA FALSE FALSE FALSE    NA

my_df$b2 == NA
## [1] NA NA NA NA NA NA NA NA NA

is.na(my_df$b2)
## [1]  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE

```

Now, since coercing TRUE and FALSE to numeric gives 1 and 0 respectively,

```
+TRUE
## [1] 1

+FALSE
## [1] 0

```

we can compute `!is.na(b2)` which is TRUE if it is not NA and FALSE if it is and then convert that to numeric using + to give the 0/1 value needed.

```
my_df %>% mutate(b3 = +!is.na(b2))

```

giving:

```
  ID b2 b3
1  2 NA  0
2  4  4  1
3  6  6  1
4  8  2  1
5 10 NA  0
6 12  6  1
7 14  1  1
8 16  1  1
9 18 NA  0

```
Please find below one possible answer using the `dplyr` library

**Reprex**

* Code

```r
library(dplyr)

my_df %>% 
  mutate(b2 = if_else(is.na(b2), 0, 1))

```

* Output

```r
#>   ID b2
#> 1  2  0
#> 2  4  1
#> 3  6  1
#> 4  8  1
#> 5 10  0
#> 6 12  1
#> 7 14  1
#> 8 16  1
#> 9 18  0

```

Created on 2022-01-20 by the [reprex package](https://reprex.tidyverse.org) (v2.0.1)